Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Mail Inbox Rule, Apple Script and Fantastical

I have a script that sends the contents of an e-mail to Fantastical. It works just fine if the target mail is selected:


tell application "Mail"

set theSelection to selection

set theMessage to item 1 of theSelection

content of theMessage

set theContent to content of theMessage

end tell


tell application "Fantastical"

parse sentencetheContent

delay 0.3

tell application "System Events"


keystrokereturnusingcommand down--CMD+Enter

delay 2


key code 53 --ESC

end tell

end tell


I created a Mail Rule that should invoke this script when any mail with Subject "NewCalEvent" comes into Mailbox. The code above doesn't work as it captures content of the currently selected mail and not the one Mail Rule is handling. How should I rewrite it to make it work properly?


Thanks

Andrej

Mac OS X (10.7.3)

Posted on May 16, 2012 10:05 AM

Reply
Question marked as Best reply

Posted on May 16, 2012 10:39 AM

Your script is working with the current selection because that is what you are telling it to do. Mail has a perform mail action with messages handler you can add to your script that gets called with a list of the messages the rule is acting on. There is a Sample Rule Action Script in the /Library/Scripts/Mail Scripts/Rule Actions folder.

7 replies
Question marked as Best reply

May 16, 2012 10:39 AM in response to Andrej64

Your script is working with the current selection because that is what you are telling it to do. Mail has a perform mail action with messages handler you can add to your script that gets called with a list of the messages the rule is acting on. There is a Sample Rule Action Script in the /Library/Scripts/Mail Scripts/Rule Actions folder.

May 17, 2012 3:50 AM in response to red_menace

I must be doing something wrong. I created a rule that should filter out 1 (one) message from my Inbox based on the Subject and run Sample Rule Action Script in order to test it.


Test result:

1. The message "This AppleScript is intended to be used as an ..." was displayed as expected.

2. All mail messages from Inbox were moved to a subfolder of another mail account. I was quite surprised. Any idea what is going on?


Thanks

Andrej

Mail Inbox Rule, Apple Script and Fantastical

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.