Before the age of real smartphones I created a Rube Goldberg-like workflow that listened for emails from my Nokia phone. The subject needed to contain a song and artist. Then the script pasted that subject line into iTunes. Then it would call my phone back via SkypeOut and as my phone was ringing it would press play in iTunes so I could hear my song through my phone. I called it Dittybot. My original blog post is gone, but here’s an Engadget article about it: https://www.engadget.com/2005-06-17-dittybot.html
At my university we use Moodle and that lets me setup a page where students can schedule one-on-one appointments with me (during office hours). When a student books a time, Moodle sends me an email with the details.
I use a rule and an Applescript to scrape the details from the email and put the booking into my calendar.
First, to anyone reading, please don't run that command!
---
I realize that:
• We're on Hacker News, and most Hacker News users will know what that command does.
• Nobody should be running random Terminal commands found on the internet without understanding what they do.
The fact remains that some child might be browsing HN, see this "automation hack", and try running it to find out what happens. There's fundamentally no good reason to post destructive commands without a warning. It isn't funny.
that’s not cool. Tricking computer users who may not be familiar with this command and which could cause data loss with real world repercussions (lost company data, lost treasured family photos etc) is not cool or funny.
For those unfamiliar with this command, it may completely remove all files from your system, resulting in a broken and unrecoverable system.
I know a handful of non-tech users that have been fooled by this over the years. Destructive pranks are not funny, and you don't know what valuable data you're putting at risk.
There are plenty of amusing pranks that don't result in random data loss.
The version with the tilde character is worse! At least with the bare slash, some versions of rm will simply refuse to run (they require --no-preserve-root). Plus, even if it works, “rm -rf /“ is likely to start at something like /bin and spew a ton of errors unless you use sudo, giving you ample time to abort before it starts wiping the stuff you care about in /home, /usr, etc.
On the other hand, with the tilde, it will just start wiping your personal files right away and will probably not run into any permission errors.
$ git clone git@github.com:dotfiles '$HOME'
Cloning into '$HOME'...
*ugh...*
$ rm -rf $HOME
*wait...*
$ cd $HOME
cd: no such file or directory: /Users/admin
*fuuuuuuuu*
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:
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.
1. It is a niche feature to Mail rules that isn't exactly marketable to the average user, but instead exists for power users that seek it out. Like many small features and secrets in macOS, it is more often discovered than known out of the box.
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.
> 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.
…In case anyone was still wondering why AppleScript is already dead.
One of the worst parts of Apple Mail is that they have entirely neglected the iOS version since the iPhone first came out. Its the same exact app afaik since iOS 1. No rules to make, not even colored flags, despite how powerful phones have gotten. My inbox stays polluted and unsifted until I open the lid on my macbook, it runs all these local rules and syncs to the email server, and my phone pulls the changes.
I thought it could be nice as a stand-in for an SSH Siri Shortcut action on iOS, because you don't need to reach out to a static IP address. It is more dynamic to be able to send an email from your phone to your Mac regardless of what network your Mac is currently on (so long as your Mac is awake).
Back in the day we used to download files from certain FTP servers via an email with the correct terms.
I never found it very interesting, but it was novel. It would have been much cooler had smartphones been around then.
To execute a Python script as a Mail rule action? Horrible.
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.
Actual title: "Use scripts as rule actions in Mail on Mac"
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.