Re: scripting mail
Re: scripting mail
- Subject: Re: scripting mail
- From: David Meieran <email@hidden>
- Date: Wed, 31 Jul 2002 14:26:55 -0400
I'll respond to your message in three stages.
On Wednesday, July 31, 2002, at 11:28 AM, Philip Aker wrote:
Greetings David,
Thanks for your input on this item. I have tried to get a solution with
YoupiKey but have only had mixed results. The following is what I have
tried with YoupiKey 1.7.0. As to where my problems were stemming from
isn't clear to me. Firstly, I had some problems with YoupiKey not
sticking to its slot in the menubar. Secondly, I had some problems
deducing how the scripts were to be entered into YK and how to use a
"Simulate Menu Key" item in a script. In the script below, I have
"shortcut "Copy" of shortcutset "Universal" supposed to copy whatever
is the current selection in Mail. Thirdly, the script would run ok BUT
mostly just for the first or second invocation. That is, I couldn't
trust it enough to be able to delete the message after I had run the
script--I'd always have to open the text file and check that the job
was actually done.
Try using Keyboard Maestro (Lite version is free). I haven't used
YoupiKey for a while but as I recall it was an .app not a .menu item,
hence its menu position can't be adjusted.
In Keyboard Maestro, click the create hot key button icon and then click
New Action > Type Keystroke and have the thing type Cmd-C. Then click
New Action > Execute Unix Script, and select the saved shell script that
directs the pbaste, etc., to a specific file (I'll come back to your
desire for multiple files in a moment). Make sure the script is
executable - type chmod 755 /path_to_script/ in the terminal followed by
the command, "rehash."
At this point we can now highlight and text in any application and it
will be added to the filename. I've tested the above and it works 100%
of the time. Try it
[end stage one; stage two to follow]
Your script offers a different approach and I'd be especially
interested to find out where you learned about 'pbpaste'.
I don't remember - MacOsXHints, perhaps. The only man page I can locate
is here:
http://www.vorlesungen.uni-
osnabrueck.de/informatik/shellscript/Html/Man/_Man_NeXT_html/html1/pbcopy.
1.html
However I'll have to make considerable adaptions because your example
doesn't account for the text file being coordinated with the current
mailbox and isn't bound to a single keystroke. Which is to say I have
about 25 mailboxes, some of which are nested, and want to be able to
run the script while I'm reviewing messages in any one of them and have
the selected text go to the correct output file. For example my
"applescript" mailbox is labeled "apple/applescript on Personal
Mailboxes" and you know it's very bad to have a slash in a Unix file
name. The name of the output file should be just a single word with the
extension ".txt". My mailbox names are always one word with C language
constraints for symbol characters ([0-9A-Za-z_]*).
[stage two...]
geez, and i thought i had a lot of mail boxes (12). still, the trick is
simple:
1. use Keyboard Maestro to set the hotkey for the clipboard -
applescript combo
2. use applescript to figure out which mailbox is current and to run the
shell script
3. use the shell script to paste Mail's clipboard into a designated
file. this could end up being one line kinda like this: "pbpaste >>
/path_to/$1"
i'll try a few experiments and get back to you later today ('stage
three')
dm
============ YoupiKey-Mail-Script ===============================
on AppendDataToFile(theFile, theData)
try
set fref to open for access file theFile with write permission
set fpos to (get eof fref) + 1
write theData starting at fpos to fref
close access fref
on error errstr number errnum
my HandleError(errstr)
end try
end AppendDataToFile
on HandleError(theErrorString)
display dialog theErrorString buttons {"OK"} default button 1 with
icon caution
end HandleError
tell application "Mail"
activate
end tell
tell application "Youpi Key"
run shortcut "Copy" of shortcutset "Universal"
end tell
tell application "Finder"
try
set clipdata to (the clipboard as string)
if length of clipdata is 0 then return
on error errstr
my HandleError(errstr)
end try
end tell
tell application "Mail"
try
set wname to (name of front window)
if wname contains "/" then
set fname to (word 2 of wname) & ".txt"
else
set fname to (word 1 of wname) & ".txt"
end if
set fpath to (path to "sdat" as string) & fname
set wdat to return & clipdata & return & "*/" & return
my AppendDataToFile(fpath, wdat)
say (fname as string)
on error errstr
my HandleError(errstr)
end try
end tell
On Tuesday, July 30, 2002, at 09:45 AM, David Meieran wrote:
On Monday, July 29, 2002, at 04:50 AM, Philip Aker wrote:
I would like to use a single key-command to append the text selection
to a text file. A text file whose name is derived from the name of
the current mailbox. Typically, I put a CR, a few delimeter
characters and another CR after the latest entry in the text file.
The messages from this list go into my "applescript" mailbox. Like
any other list, there's a lot of dross along with the good stuff. I
only need the good stuff in my text file--which for this list is
called "applescript.txt" and is located in a folder along with the
text files from all my other lists. When I want to find something
later on, then I just batch-regexp through the file(s).
1. Create a shell script ("akerscript")
#!/bin/sh
# pasteboard script
cat >>/Users/aker/Documents/applescript.txt <<EOF
`date`
`pbpaste`
EOF
2. using your favorite keyboard shortcut app (Keyboard Maestro,
YoupiKey, etc.), attach a key to this sequence:
i) type the Cmd-C key
ii) launch unix script "akerscript"
and you're done.
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.