Home > Articles

  • Print
  • + Share This
This chapter is from the book

This chapter is from the book

Assign a Folder Action

AppleScript, the built-in application-aware programming language included in Mac OS X, can be harnessed to extend the functionality of the Finder. AppleScript gives you the ability to assign folder actions to individual folders in the system. What the script can do is limited only by your imagination.

NOTE

Key Term - Folder action—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 performs some function.

Apple provides a few sample folder action scripts, in the Scripts folder inside the main system Library. These include a script which will display the folder's comments in a dialog box when you open the folder in the Finder (useful for making sure that other users are told some useful piece of information if they wander into the folder); one which 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 sub-folders of that folder. If you like, you can modify these scripts or use them as examples for new scripts that you write.

Figure 3.12Figure 3.12

  1. Enable Folder Actions

  2. Folder actions are controlled from the contextual menu which you open by Control+clicking or right-clicking on or inside any Finder window or the Desktop.

    Open the contextual menu; select Enable Folder Actions. This turns on Folder Actions globally and allows you to assign them anywhere in the system.

  3. Navigate to the Folder You Want to Configure

  4. 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.

  5. Attach a Folder Action

  6. 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.

  7. Choose a Script

  8. You can choose one of the many sample scripts in this folder or any other script you have written or downloaded. Choose the script file and click Choose to assign the script to the selected folder.

    Inside the AppleScript folder in the Applications folder, you'll find another collection of folder action scripts you can attach to folders. Use the built-in navigator to locate these scripts and attach them.

    NOTE

    You can assign multiple scripts to the same folder, if you like.

  9. Test the Folder Action

  10. Depending on what the script does, it will be triggered by different actions—adding 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 that a dialog box pops up showing you the comments you entered. In the example shown here, the add - new item alert.scpt, attached to the Drop Box folder, pops up a notification whenever anybody puts a new item into your Drop Box folder.

  11. Edit a Folder Action Script

  12. After a script has been attached to a folder, you can edit the script file 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 you want to edit.

    After making your changes, click Save and test the folder action again.

  13. Configure Folder Actions

  14. 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.

  • + Share This
  • 🔖 Save To Your Account