Folder Actions
A folder action is a behavior that occurs automatically when certain events take place in a designated folder in the Finder. Folder actions aren’t implemented as application, but as scripts with certain handlers which, if present, are called when the corresponding event takes place. For example, when applied to a folder, the following folder action script displays a message whenever files are moved or saved there:
on adding folder items to this_folder after receiving these_items
tell application "Finder"
set this_name to the name of this_folder
end tell
display dialog ((the count of these_items) as string) & ¬
" items have been added to folder "" & this_name & ¬
""." buttons {"OK"} default button 1
end adding folder items toTo create a folder action, save the AppleScript as a script file
(with a .scpt) extension in the
~/Library/Scripts/Folder Action Scripts folder
(or /Library/Scripts/Folder Action Scripts if
you want the script to be available for all users). To apply the
folder action script to a folder, Control-click on a folder, and
select “Attach a Folder Action”
from the context menu, as shown in Figure 14-5.

Figure 14-5. Attaching a Folder Action script to a folder
After selecting this item, the window shown in Figure 14-6 appears, taking you to the
~/Library/Scripts/Folder Action Scripts folder, from which you can select and choose the folder action script to ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access