I set up Mail to constantly monitor an email address. Anytime it receives an email, I want it to trigger an applescript that will grab the subject and content info in the email and copy to Filemaker. I created an applescript that does this:
tell application “FileMaker Pro Advanced”
activate
delay 5
end tell
tell application “Mail”
set theSelection to every message of mailbox “INBOX” of account 1
set theMessage to item 1 of theSelection
set theSubject to subject of theMessage
set theContect to content of theMessage
end tell
tell application “FileMaker Pro Advanced”
activate
if (exists database "Tasks.FP7") then
go to database "Tasks.FP7"
else
getURL "fmp7://192.168.0.101/Tasks.fp7"
delay 5
end if
tell database "Tasks"
tell table "Requests"
create record
tell last record
set cell "title" to theSubject
set cell "Assigned To" to "Michael"
set cell "Notes" to theContect
end tell
end tell
end tell
end tell
tell application “Mail”
activate
set theSelection to every message of mailbox “INBOX” of account 1
set theMessage to item 1 of theSelection
delete theMessage
end tell
However, here is the problem… the incoming emails do not get placed in the Inbox until AFTER the applescript has completed execution. Therefore, there is no way for me to SELECT the incoming email in order to get the subject and content info. I tried adding delays to the applescript, but still, the incoming email will not appear in the Inbox until the applescript has finished - nomatter how long the delays.
I need to figure out how to select the incoming email after it arrives, but before it gets placed in the Inbox. Or I need to figure out a way to delay the applescript until Mail completes the receive process.