Chapter 11. Linking Scripts to Folders with Folder Actions
Imagine: your Mac reminds you to clean the sink whenever you open your Applications folder. You automatically see a dialog box whenever someone on your network drops a file in your Public folder. And your desktop automatically cleans itself up when you fill it with too many icons.
Now stop dreaming. Everything you just imagined is only a script away, thanks to the special folder actions feature you get with AppleScript and Mac OS X.
Note
If you’ve used Mail rules before (Sidebar 9.4), you’ll instantly understand the power of folder actions. That’s because Mail rules and folder actions are based on the same idea: triggering scripts automatically when something happens on your Mac.
A folder action is an AppleScript like any other. The difference is that you can attach a folder action to a specific folder—and have the script run automatically when you do something to that folder. You can trigger a folder action when you open a folder, close a folder, or copy items into a folder, for example. With triggers like these, the scripting possibilities are truly limitless.
Note
The example scripts from this chapter can be found on the AppleScript Examples CD (see Sidebar 2.1 for instructions).
Enabling Folder Actions
Don’t lose sleep imagining the possibilities—yet. Before you start linking up scripts to your folders, you first have to turn on folder actions on a system-wide level. Luckily, that’s a simple procedure: just Control-click anywhere ...
Get AppleScript: The Missing Manual now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.