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.

A folder with an attached script
Figure 26-1. A folder with an attached script

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

Get AppleScript in a Nutshell 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.