Folder Actions

A folder action is a behavior that occurs automatically when certain events take place in a designated folder in the Finder. Folder actions are not implemented as applications, but as scripts (but they seem to have found their way into this chapter anyway). As with digital hub scripting, your script has certain handlers which, if present, will be called when the corresponding event takes place.

Any scripts to be used as folder action scripts should live in ~/Library/Scripts/Folder Action Scripts. Alternatively they can live in /Library/Scripts/Folder Action Scripts, and some example scripts are located there; but the former, the one in your user library, is the default.

Setting up a folder action involves the association of a script with a folder. To make such an association is to attach the script to the folder; to break the association is to remove the script from the folder. The script is not actually moved; attachment and removal are conceptual, not physical, and are performed through System Events (see Section 21.2.3), which ties a folder and a script together through a folder action object. It is up to System Events to maintain these folder action objects and to respond correctly when an appropriate action in the Finder takes place. So System Events must be running in order for folder actions to work; that is why, when you enable the folder actions mechanism, System Events is added to your Startup Items.

In general, you don’t have to worry yourself with the ...

Get AppleScript: The Definitive Guide 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.