Folder Actions
Folder Actions is a feature of OS X that lets you associate AppleScript scripts with folders. A Folder Action script is executed when the folder to which it is attached has items added or removed, or when its window is opened, closed, moved, or resized. The script provides a handler that matches the appropriate format for the action, as described in this chapter.[1]
Documentation
- AppleScript Language Guide - Folder Actions Reference [EN] @ Mac Developer Library
- Watching Folders [EN] @ Mac Developer Library
Examples
- Set up a debug functionality
- Copy the files fa-debug.applescript and fa-debug.sh into a directory e.g. cp 'fa-debug.applescript' 'fa-debug.sh' "${HOME}/dev".
- Adjust the path to the file fa-debug.sh in the file fa-debug.applescript.
- Compile the AppleScript e.g. osacompile -o 'fa-debug.scpt' 'fa-debug.applescript'
- Create a soft link for the AppleScript into the Folder Actions script folder e.g. ln --symbolic "${HOME}/dev/fa-debug.scpt" "${HOME}/Library/Scripts/Folder Action Scripts".
- Start the macOS application 'Folder Actions Setup' e.g. open -a '/System/Library/CoreServices/Applications/Folder Actions Setup.app'.
- Set the box 'Enable Folder Actions'.
- Add a folder e.g. ${HOME}/tmp.
- Set the box fa-debug.scpt.
- Monitor the log file e.g. tail --follow "${HOME}/dev/folder_actions/logs/debug.log".
- Create a new file in the folder e.g. touch "${HOME}/tmp/test.txt".