One of the hidden gems in OS X is a scripting service called Folder Actions, where you can bind an AppleScript to run whenever the contents of a specified folder are changed. This feature can be exceptionally useful, not only for helping you organize files and folders, but also for helping you monitor aspects of your system.
Unfortunately Apple does not promote Folder Actions, and perhaps they might someday go the wayside and be gone from OS X, but for now while they are still around you might be able to make good use of them.
To enable folder actions, you will need to activate the script menu from the AppleScript editor utility:
- Open AppleScript Editor (or “Script Editor”) in the Applications > Utilities folder
- Go to this program’s preferences
- Check the box in the General section to “Show Script menu in menu bar.”
The menu that appears on the left-hand side of your menu bar should look like a little scroll, in which you can choose “Configure Folder Actions” from the “Folder Actions” menu. This will open a small panel, where on the left you can add watch folders to the list, and then select each and bind separate scripts to them by clicking the plus button under the column on the right.
Folder Action scripts are simply AppleScripts, so if you are familiar with Apple’s scripting language then you can create some fairly complex handling routines for your watched folders; however, if not then you can still make use of Folder Actions with Automator, Apple’s simplified workflow-based scripting routine for OS X:
- Open Automator and press Command-N to create a new workflow
- Select “Folder Action” as the type of workflow
- Choose the desired folder to watch from the top of the workflow
- Add the various actions you desire to the workflow, to create your scripted routine.
- Save the workflow and exit.
By choosing “Folder Action” as the Automator workflow type, the saved file will be stored in the username > Library > Workflows > Applications > Folder Actions directory. You will then be able to change which folders this script is bound to in the Folder Actions Setup utility.
By starting with Automator, you can implement some fairly robust scripts to bind to folders, and when you need more versatility, you can then migrate to performing the same actions and more in AppleScripts.
It’s interesting that Folder Actions are tied to two other all but moribund Apple technologies, Apple Script and Automator. Of course these were never intended to be mass market tools. And they haven’t been. That’s no reason to dismiss them, of course; the Mac has plenty of tools for techies. Hopefully this will remains the case, despite the fact that Apple never highlights these features. I haven’t looked lately, but I believe there are resources available for people interested in using and sharing Apple Script scripts and techniques, and some for automator as well. Unfortunately these are apparently not well enough known for Topher to mention them; however, anyone who has initiative enough to test the waters with Apple Script and Automator (and Folder Actions) should be able to find what they need through their own research on the Web.
Why is it that it works very well, but then the following day it stops working ?