Folder Actions

From RaySoft

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

Examples

Set up a debug functionality
  1. Copy the files fa-debug.applescript and fa-debug.sh into a directory e.g. cp 'fa-debug.applescript' 'fa-debug.sh' "${HOME}/dev".
  2. Adjust the path to the file fa-debug.sh in the file fa-debug.applescript.
  3. Compile the AppleScript e.g. osacompile -o 'fa-debug.scpt' 'fa-debug.applescript'
  4. 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".
  5. Start the macOS application 'Folder Actions Setup' e.g. open -a '/System/Library/CoreServices/Applications/Folder Actions Setup.app'.
    1. Set the box 'Enable Folder Actions'.
    2. Add a folder e.g. ${HOME}/tmp.
    3. Set the box fa-debug.scpt.
  6. Monitor the log file e.g. tail --follow "${HOME}/dev/folder_actions/logs/debug.log".
  7. Create a new file in the folder e.g. touch "${HOME}/tmp/test.txt".

References