13.5. Folder Actions
The Mac allows you to attach a script to a folder. If you have attached a script to a folder, that script is automatically executed whenever one of five specific folder actions occurs. This action causes a specific handler in your script to be called. The following table summarizes the folder action and the corresponding handler that gets called.
Folder Action | Handler that GEts Called |
---|---|
opening a folder | opening folder folder |
closing a folder window | closing folder window for folder |
adding items to a folder | adding folder items to folder after receiving fileList |
removing items from a folder | removing folder items from folder after losing fileList |
moving or resizing a folder window | moving folder window for folder from boundingRectangle |
These handlers get called when one of the listed actions occurs on a folder that is open in the Finder. These handlers each get passed an alias to the folder attached to the script. The alias is passed because you can attach the same script to as many folders as you like. You can test the argument to see which folder caused the handler to be called.
You don't have to handle all five of these folder actions. Instead, you just write the handlers for the actions you want to handle.
A list of files is also passed to the adding items to and removing folder items from handlers. In all cases, these actions only work for folders that are open in the Finder.
Make sure you distinguish a folder action from a droplet, which was covered in Chapter 10. A folder ...
Get Beginning AppleScript® 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.