How to attach an action to a Mac folder for automatic workflows
Folder Actions are one of many hidden gems in macOS. You can set an action to occur whenever the contents of a folder are changed. This can be a simple action drawn from a list that Apple provides with macOS, an AppleScript, or a workflow produced in Automator. Automator lets you extend these actions into Terminal shell scripts and other languages.
You can use Folder Actions for a lot of disparate purposes:
- Resize images or convert them another file format when they’re added to a folder.
- Provide a popup alert when items are added to a folder through an automated process that you otherwise wouldn’t know had completed.
- Add a downloaded MP3 to the Music app.
Control-click any folder in the Finder and choose Services > Folder Actions Setup in Monterey. In early versions of macOS, the option appears in the main lists of contextual items. To avoid the malicious and accidental installation of Folder Actions, macOS requires a confirmation step that can’t be automated: click Run Service in the Confirm Service dialog. This adds the current folder to the Folders with Actions list without adding actions.
The Folder Actions Setup window appears with a dialog already open that reads Choose a Script to Attach. This list includes ones that Apple seeded, locating them inside the /Library/Scripts/Folder Actions Scripts
folder. Any scripts installed by apps or that you’ve created and placed inside your Home directory’s ~/Library/Scripts/Folder Actions Scripts
folder appear as well.
Folder Actions Setup shows all folders macOS is watching. Select any folder to see which scripts are attached. You can use checkboxes to toggle scripts on or off and folder watching for each folder on or off.
You can create Folder Actions in a numbers of ways:
- Use an item Apple provides in the dialog that appears when you invoke Folder Actions Setup. These mostly relate to image processing.
- Create a Folder Action in Automator using its broader set of tools. This can include passing information to an AppleScript, JavaScript, or shell script.
- Write your own AppleScript to perform a task.
AppleScript is relatively easy to write and can be adapted from simple recipes. Apple offers some in its developer documentation of the feature. I also recommend reading Jessica Thornsby’s article.
You can use AppleScript as a simple bit of connective tissue, too. For instance, I have a workflow in Flying Meat’s Retrobatch Pro image-processing software that puts a border around an image. A simple AppleScript turns a folder into a spring-loaded passthrough for the Retrobatch Pro operation.
If you need more sophisticated watched-folder behavior, turn to Hazel from Noodlesoft, a supercharged third-party version of Folder Actions.
Ask Mac 911
We’ve compiled a list of the questions we get asked most frequently, along with answers and links to columns: read our super FAQ to see if your question is covered. If not, we’re always looking for new problems to solve! Email yours to [email protected], including screen captures as appropriate and whether you want your full name used. Not every question will be answered, we don’t reply to email, and we cannot provide direct troubleshooting advice.
For all the latest Technology News Click Here
For the latest news and updates, follow us on Google News.