Alright… I’ve got a dilemma. I need to be able to have an applescript that be attached to a rule in Mail.
When the script is run, it parses the content of the email (which is already formatted ready for parsing from a PHP server-side form) and adds it to an Excel template.
I have the parsing subroutine down right (it works with just text for input) but I need to be able to have it automated within Mail.
Any suggestions? I have a feeling I’m making a stupid mistake.
using terms from application "Mail"
on perform mail action with messages theMessages
tell application "Mail"
set theMessages to selection
set theContent to the content of theMessages as string
end tell
parseMessage(theContent)
end perform mail action with messages
end using terms from
on parseMessage(theContent)
set AppleScript's text item delimiters to {" "}
set certFrom to text item 2 of theContent as string
set Occassion to text item 4 of theContent as string
set annivYears to text item 6 of theContent as string
set dateofAniv to text item 8 of theContent as string
set nameS to the text item 10 of theContent as string
set recepNumber to the text item 12 of theContent as string
set recepAddress to the text item 14 of theContent as string
set requestAddress to the text item 16 of theContent as string
set requestName to the text item 18 of theContent as string
set requestNumber to the text item 20 of theContent as string
tell application "Finder"
open "blahblahblahblah:Request Form.xls"
end tell
tell application "Microsoft Excel"
set certF to value of (range "A4")
set value of (range "A4") to (certF & " " & certFrom)
set occaS to value of (range "A6")
set value of (range "A6") to (occaS & " " & Occassion)
set value of (range "B17") to recepAddress
set value of (range "B20") to recepNumber
set value of (range "A15") to nameS
set value of (range "B8") to annivYears
set value of (range "D8") to dateofAniv
set value of (range "B22") to requestName
set value of (range "B23") to requestAddress
set value of (range "B25") to requestNumber
end tell
end parseMessage