Team LiB   Previous Section   Next Section

Chapter 26. Folder Actions Extension

Folder actions allow the scripter to trigger specified AppleScripts when certain folder behaviors take place, such as the adding or removing of files from the directory. You can attach or associate more than one script or folder action with a folder. There are a lot of practical uses for folder actions, such as logging activity in a certain directory or doing automatic backups of files that are added to a particular folder. You can attach a script to a folder in one of two ways:

  • Control-click the folder and select the "Attach a folder item..." contextual-menu item

  • Use AppleScript to attach an action or script code to a folder

When a folder has an attached action, its folder icon changes to include a little script icon, as in Figure 26-1.

Figure 26-1. A folder with an attached script
figs/ascr_2601.gif

The commands that you use in your script (see the "Dictionary commands" section later in this chapter) derive from the Folder Actions suite of five commands. You can find these command definitions in the startup disk:System Folder:Scripting Additions:Standard Additions set of scripting additions. So before we become completely confused, let's go over this one more time:

  • Folder actions are AppleScripts that execute when certain actions take place with the folder, like adding items to it or moving it.

  • Folder action commands constitute the Folder Actions suite of the Standard Additions osax and the dictionary commands that derive from the Folder Actions extension. Both sets of commands are described in this chapter.

  • You have to attach folder actions to the folders that you want these actions to control. You can attach a script with AppleScript code or a contextual menu command. Contextual menus are produced by selecting the folder and holding down the Control key.

  • You can attach more than one folder action to a folder by either including more than one command or handler (e.g., on opening folder theFolder...end) in an attached script or by attaching multiple scripts to a folder. Before it is attached to a folder, the script has to be saved as a compiled script, not an applet (see Chapter 2 ).

  • You can group all of your folder action scripts in the System Folder:Scripts: Folder Action Scripts folder.

In Folder Actions 1.5.5, an extension that installs with Mac OS 9.1, the "Icon\n" file is only created inside a folder if a script is actually attached to the folder. In Folder Actions 1.4.3 and earlier, Folder Actions would create an invisible "Icon\n" file in any folder that you control-clicked, whether or not an action was attached to that folder.

    Team LiB   Previous Section   Next Section