Folder actions are notoriously slow AND they’re just an extra layer on top of launchd. I’ve found that using launchd to run your script improves the reliability of AppleScripts (YMMV).
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Disabled</key>
<false/>
<key>Label</key>
<string>com.domain.myapplescript</string>
<key>Program</key>
<string>/usr/bin/osascript</string>
<key>ProgramArguments</key>
<array>
<string>osascript</string>
<string>/Library/Scripts/myapplescript/myapplescript.scpt</string>
</array>
<key>WatchPaths</key>
<array>
<string>/Volumes/path/to/folder/to/watch</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>onDemand</key>
<true/>
</dict>
</plist>
Call this file com.domain.myapplescript.plist and put it in to your (not the systems) /Library/LaunchAgents/ folder.
At restart/login launchd will see this file and act on it. You can control it from the command line with
launchctl load ~/Library/LaunchAgents/com.domain.myapplescript.plist
Posted under AppleScript
This post was written by stetho on June 7, 2010
