Six Colors
Six Colors

by Jason Snell & Dan Moren

This Week's Sponsor

End users aren't your enemy! Kolide gets users to fix their own device compliance problems–and unsecure devices can't log in. Click here to learn how.

By Jason Snell

Generation gap: Using Shortcuts with Folder Actions

Nothing like mixing a Mac feature from 2002 with one from 2021.

In my quest to improve my Apple analyst-call transcripts by using OpenAI’s Whisper technology, I’ve ended up in a position where I need to create an automation on my Mac that runs when an item is placed in a folder. In doing so, it turns out that I unearthed several layers of Apple automation sediment—and discovered a place where the company could get a quick win by declaring an ancient feature to be new and improved.

Chain of events

Here’s what led me here: I capture Apple’s quarterly analyst call with Audio Hijack and thought I could use its automation features to kick off the transcription of a segment of the call every few minutes.

It didn’t work. While Audio Hijack lets you run Shortcuts and shell commands from its scripting interface, those methods block the main thread of Audio Hijack, locking up the interface. Not acceptable, given how long it takes for Whisper to run.

As a result, I needed to find a way to automatically process a new recording without using Audio Hijack’s scripting interface to do it. It was clear what was required: I would tell Audio Hijack to move the finished recording to a different folder, and then run a script the moment the file was added to that folder.

I needed a utility that could watch a folder and then process any item that was added. And I had some choices.

Option one: Use Hazel

I use Noodlesoft’s $42 Hazel for various clean-up jobs on my Mac. Hazel watches folders on your Mac and then acts on the files inside.

I could’ve used Hazel to do this job, but I decided not to for a few reasons. I’ve found that connecting scripting into Hazel actions can be complicated and brittle. It can be done, but sometimes my actions break and I have to fix them, and I don’t really want to do that during my transcriptions if I can help it. Its Shortcuts support also seems suspect… I have tried to use it with little success.

But also, why use a third-party utility when there’s an equivalent feature built into the operating system itself? Because while many people will have forgotten, or perhaps never known, macOS has had this built-in functionality for ages.

Folder Actions via AppleScript

Folder Actions were a feature of Mac OS 9, and they were introduced back into Mac OS X with version 10.2 “Jaguar” in 2002. And more than twenty years later, they’re still there. Folder Actions used to be accessible by control-clicking on any folder in the Finder, but that easy access was ripped out years ago. In today’s macOS (and yes, it works on macOS Sonoma), you need to open the Folder Actions Setup utility, which is located in the /System/Library/CoreServices/Applications/ folder.

Folder Actions is pretty clever—you can run scripts when items are added or removed from a folder, when the folder is opened or closed, or when the window of that folder is moved in Finder.

Unfortunately, this is a feature that is wired directly into AppleScript. So in order to use a version of my existing shortcut with Folder Actions, I needed to write a three-line AppleScript script:

on adding folder items to this_folder after receiving added_items
    tell application "Shortcuts Events" to run the shortcut named "Apple Result Transcriptor" with input added_items
end adding folder items to

Pretty dumb — for those keeping score we’ve now gone from Audio Hijack to AppleScript to Shortcuts in order to get what we want. (I could’ve rewritten my Shortcut in AppleScript, but… I don’t want to do that!) And yet also pretty brilliant, because I’m using a 21-year-old OS feature to run a Shortcut, an automation system that didn’t appear on the Mac until 2021.

Don’t forget Automator

Automator also has Folder Actions.

I should mention that there is an additional built-in way to act on items added to a folder in macOS: Automator. Automator, introduced to Mac OS X three years after Folder Actions, uses a different pathway to the same result.

When you create a new Automator action, you’re asked to choose a type for your document. Among the types is Folder Action, which runs when files and folders are added to a specific folder. I could’ve used this method, but I would again have ended up using a shell command or an AppleScript to run my existing Shortcut.

A new feature that already exists

On iOS and iPadOS, you can set various triggers to run Shortcuts automatically. It’s clever and useful. I have a Shortcut that turns on Do Not Disturb when my iPhone connects to the Bluetooth speaker in my shower—and turns it off again when it disconnects. But Shortcuts contains no such automation functionality on the Mac.

That’s pretty dumb. It’s really useful to be able to run automations when certain events happen, such as—just for one example—when files are added to a folder. Given that Folder Actions are old enough to drink, perhaps the underlying tech might not be the most modern and efficient way to implement such a feature. Maybe there’s a modern, better way.

What I’m saying, though, is that the Shortcuts team should lift the entire concept of Folder Actions (from both AppleScript and Automator) and implement (or re-implement) it for Shortcuts. Along with all the other automation triggers that iPhone and iPad have that, for some reason, just aren’t available on the Mac.

Sure, I can solve these problems on the Mac via other means, but I shouldn’t have to. macOS should provide this functionality itself.

If you appreciate articles like this one, support us by becoming a Six Colors subscriber. Subscribers get access to an exclusive podcast, members-only stories, and a special community.

Search Six Colors