23. Assign a Folder Action BEFORE YOU BEGIN 13 Create a New Folder SEE ALSO 36 Allow Others to Share Your Files 11 Automate a Recurring Task AppleScript, the built-in application-aware programming language included in Mac OS X, can be harnessed in order to extend the functionality of the Finder. AppleScript gives you the ability to assign folder actions to individual folders in the system. A folder action is a script (a simple human-readable program) that you attach to a folder; triggered by certain events, such as when you open or close the folder or add an item into it, the folder action script will perform some function. What the script can do is limited only by your imagination . 23. Assign a Folder Action Apple provides a few sample folder action scripts in the Scripts folder inside the main system Library . These include a script that will display the folder's comments in a dialog box when you open the folder in the Finder (useful for making sure other users are told some useful piece of information if they wander into the folder); one that pops up a dialog box informing you when any new items are added to the folder; and one that, when you close the folder, closes any windows showing subfolders of that folder. If you like, you can modify these scripts or use them as examples for new scripts that you write. 1. | Enable Folder Actions Folder actions are controlled from the contextual menu, which you can open by Control +clicking on or inside any Finder window or on the Desktop, or by right-clicking if you have a two-button mouse. Open the contextual menu; select Enable Folder Actions . This turns on Folder Actions globally and allows you to assign them anywhere in the system. | 2. | Navigate to the Folder You Want to Configure Open a Finder window and navigate to the folder to which you want to assign an action script. You can set up folder actions either from within the folder in question, or in the folder above it in the hierarchy. | 3. | Attach a Folder Action Control +click or right-click the selected folder and select Attach a Folder Action from the contextual menu. A file selector window opens, by default starting in the global Folder Action Scripts folder in /Library/Scripts . | 4. | Choose a Script You can choose from one of the many sample scripts in this folder, or any other script that you have written or downloaded. Choose the script file and click Choose to assign the script to the selected folder. NOTE You can assign multiple scripts to the same folder, if you like. Inside the AppleScript folder in the Applications folder, you'll find another collection of folder action scripts that you can attach to folders. Use the built-in navigator to locate these scripts and attach them. | 5. | Test the Folder Action Depending on what the script does, it will be triggered by different actionsadding an item to the folder, opening or closing the folder, and so on. Make sure that the folder reacts properly when you trigger it. For instance, if you selected the open - show comments in dialog.scpt script, first use the Get Info panel to add a comment to the folder. Then open the folder and make sure a dialog box pops up showing you the comments you entered. In the example shown here, the add - new item alert.scpt , attached to your Drop Box folder, pops up a notification to tell you whenever anybody puts a new item into your Drop Box folder. | 6. | Edit a Folder Action Script After a script has been attached to a folder, you can edit the script directly to modify its behavior. Control +click the folder to view the contextual menu, open the Edit a Folder Action submenu, and select the script that you want to edit. After making your changes, click Save and test the folder action again. | 7. | Configure Folder Actions You can manage all the folders in the system that have folder actions attached at once. Control +click or right-click on or inside any Finder window or the Desktop to display the contextual menu and select Configure Folder Actions . A panel opens up that lists all configured folders and all the scripts assigned to each one. You can turn the individual scripts on and off, add or remove configured folders, and add or remove scripts from folders. Select any script and click the Edit Script button to modify the script so that it does exactly what you want. If you have a lot of folder actions to manage, this is the most direct way to control them all. | |