Re: scripting mail
Re: scripting mail
- Subject: Re: scripting mail
- From: David Meieran <email@hidden>
- Date: Wed, 31 Jul 2002 15:42:53 -0400
[stage 3; see previous message for earlier stages]
this should do it for the applescript:
on HandleError(theErrorString)
display dialog theErrorString buttons {"OK"} default button 1 with
icon caution
end HandleError
set fpath to "whatever is appropriate"
tell application "Mail"
activate
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
say (fname as string) -- fun for whole family
on error errstr
my HandleError(errstr)
end try
do shell script ,
("/your_path_to_script/your_script " & fpath & fname)
end tell
now, for the shell script:
cat >>$1<<EOF
`date` # remove this line if you don't want the date
`pbpaste`
/*
EOF
now, go back and change your keyboard maestro shortcut to execute the
applescript instead of the shell script.
this procedure (using keyboard maestro, the applescript and the shell
script) should accomplish exactly what you want: append highlighted
text in an mail message to a file all by hitting one key (e.g., F1).
of course, be careful what you wish for - you could end up finding it so
easy to create massive amounts of data that you'll never find time to
make use of it... :)
notes -
1. if the files in your script don't exist you may want to add another
line to either the applescript or the shell script to create it before
using the pbpaste command.
2. if the path to your text files varies according to the mailbox you'll
need to add another couple lines to select the appropriate path
let me know how it goes...
dm
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.
>
>
Your script offers a different approach and I'd be especially
>
interested to find out where you learned about 'pbpaste'. 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_]*).
>
>
>
Philip
>
>
>
>
>
============ 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.