Just wondering if someone could help me with a Mail.app Rule script. The gist is I get a monthly report from my employer and want to save it, edit it in Tex-Edit Pro, and import it to FileMaker. The last two parts I have figured out. I only recently realized the first step became possible and triggerable by a Mail rule. So basically I want to grab the email which has a unique subject and save it as a text file.
right now this is what I have:
where DTR is the name of my rule in Mail
[color=blue]
using terms from application “Mail”
on perform mail action with messages theMessages for rule “DTR”
tell application “Mail”
try
save theMessages in “MonthEndDTR.txt” as “TEXT”
on error
display dialog “oops!”
end try
end tell
end perform mail action with messages
end using terms from
[/color]
I am running 10.3.1 and am pretty sure there a stupid syntax error in there somewhere. . . lil’ help??
Is the information you want in the body of the message, or is it attached to the email?
That’s an important piece of information since that determines how you extract the data out of mail.app. Simply trying to save the message won’t cut it.
Additionally, if the message body contains the information you want, you don’t need to save it to disk at all - you can transfer it straight into TexExit (and may be able to manipulate it in AppleScript without invoking TexEdit at all - but that’s another issue)
the data is in the body of the message. I was going the save route because I was doing that step manually before and the rest of the script is already set up to do it in Tex-Edit. The Tex-Edit segment uses some grep functions that I don’t think are available in Applescript. It reformats some dates and also change the data to comma delimited text.
Before:
“. 10-NOV-2003 027297-1 50 Shmoe, Joe and Jane”
After:
“11/10/2003,027297-1,50,Schmoe,Joe,Jane”
Here is that code:
[color=blue]
replace window 1 looking for “^l” replacing with “^c”
delete text from line 1 to line 15 of window 1
set n to (number of lines)
delete text from line (n - 7) to line n of window 1
replace window 1 looking for "([0-9])(,)([0-9])" replacing with "^1^3" with grep
replace window 1 looking for "-JAN-" replacing with "/01/"
replace window 1 looking for "-FEB-" replacing with "/02/"
replace window 1 looking for "-MAR-" replacing with "/03/"
replace window 1 looking for "-APR-" replacing with "/04/"
replace window 1 looking for "-MAY-" replacing with "/05/"
replace window 1 looking for "-JUN-" replacing with "/06/"
replace window 1 looking for "-JUL-" replacing with "/07/"
replace window 1 looking for "-AUG-" replacing with "/08/"
replace window 1 looking for "-SEP-" replacing with "/09/"
replace window 1 looking for "-OCT-" replacing with "/10/"
replace window 1 looking for "-NOV-" replacing with "/11/"
replace window 1 looking for "-DEC-" replacing with "/12/"
replace window 1 looking for "([0-9]{2}/)([0-9]{2}/)([0-9]{4})" replacing with "^2^1^3" with grep
replace window 1 looking for "." replacing with "@"
replace window 1 looking for " " replacing with "@"
replace window 1 looking for "," replacing with "@"
replace window 1 looking for " " replacing with "@"
replace window 1 looking for "@@" replacing with "@"
replace window 1 looking for "@@" replacing with "@"
replace window 1 looking for "@" replacing with ","
replace window 1 looking for "^c," replacing with "^c"
replace window 1 looking for "and," replacing with ""
replace window 1 looking for "[,][A-Z]" replacing with ""
replace window 1 looking for "[,][A-Z][\.\]^c" replacing with "^c" with grep
set character 1 of window 1 to ""