Use scripts as rule actions in Mail on Mac
support.apple.com
support.apple.com
I use a rule and an Applescript to scrape the details from the email and put the booking into my calendar.
1. Apple Mail has had this feature for the last 20 years. If macOS users to whom that feature is of interest are only now realizing it exists, this speaks volumes for Apple’s documentation and marketing.
2. The page says you can use AppleScripts as rule actions. It never tells you how. No sample scripts to use or learn from. No links to the documentation you’ll need to write your own.
Here’s a better third-party introduction from 2005(!) which includes a couple rule action examples:
http://preserve.mactech.com/articles/mactech/Vol.21/21.09/Sc...
TBH, after 6 years rusting in maintenance mode, all its documentation long buried in archive, and the department responsible eliminated entirely, I am surprised Apple would still want to draw any attention to AppleScript at all. They only set up the unwary for disappointment later, once they discover for themselves the platform is already a walking corpse. That is no way to sell product. Alas, post-Jobs Apple cares little for joined-up thinking, or even motivation to do a half-decent job.
Let’s hope the Shortcuts team can eventually make a half-decent success of their product, because AppleScript automation has zero future. That said, if Ventura Mail still can’t use Shortcuts as rule actions then it doesn’t bode look great for them either.
2. It is pretty obvious from selecting the rule when it prompts you to open a script in Finder. Anyone interested in learning AppleScript can search it online or in their documentation, they're not going to distill the full scope and usage for AppleScript for every corner of the operating system where it can be utilized.
I also hope Shortcuts continues to include the AppleScript action, since Automator will soon be gutted and regular users won't know how to invoke osascript from the command line. There are still occasional additions to the AppleScript dictionary, a few last year even for the iWork suite.
…In case anyone was still wondering why AppleScript is already dead.
You need to write an AppleScript which calls `do shell script` to run the Python script, passing data to the Python script via argv or temp file (`do shell script` doesn’t support stdin so you’ve got the added pain of ensuring correct shell quoting and/or file wrangling).
Also, if if you want to pass anything more complex than short simple strings to the Python script then you’ll need to encode that data into XML or JSON which Python can trivially parse out of the box. AS’s own stdlib support is dismal, however, so you’ll need to roll your own code or rummage around online for third-party AS libraries to encode the Mail data in one of those formats.
Be aware too that `do shell script` does not read your `.zprofile` environment settings, so you’ll have to specify the full path to your `python3` interpreter wherever you’ve got that installed.
You can attach an AppleScript script to a Mail rule. For example, you could have an incoming message trigger a script that copies information from the message and pastes it into a database that works with Script Editor.
Submitters: "Please use the original title, unless it is misleading or linkbait; don't editorialize."