You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

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

Mail rules that contain AppleScript pass the wrong message

When use AppleScript with Mail rules, Mail passes the wrong message to AppleScript.


If the AppleScript is in an Inbox rule, it runs on whatever email is highlighted in the inbox.


If the rule is triggered by a Mail Act-on keystroke, it run on an adjacent message to the one selected.


When triggered manually, the script works as expected, and on the selected message.


Same problem as here:

https://discussions.apple.com/thread/250106018

https://discussions.apple.com/thread/4820345

https://stackoverflow.com/questions/48304651/mail-apps-rules-are-sending-the-wrong-messages-to-applescript


Happens with all scripts, but this one is short enough to embed here:


global FlName

tell application "Mail"
   set theMsg to selection
   open selection
   set Dialogresult to the button returned of ("Process this email and Print as PDF" buttons
       {"Yes", "No"} default button "Yes")
   if Dialogresult is "Yes" then
...


Screenshots of rules:


MacBook Pro 13", macOS 10.13

Posted on May 11, 2020 3:16 PM

Reply
Question marked as Top-ranking reply

Posted on May 11, 2020 6:10 PM

The AppleScript you wrote will not function in a Rule. There is special syntax for rule processing.

This article has examples of how to write an AppleScript to be triggered by a Mail Rule.

http://preserve.mactech.com/articles/mactech/Vol.21/21.09/ScriptingMail/index.html

Similar questions

2 replies

Mail rules that contain AppleScript pass the wrong message

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