An alternative way, slightly more low-level than folder actions, but I suspect more flexible, is to use launchd to watch a folder.
See launchd.plist(5)
, or the overview documentation for launchd (unfortunately, this overview documentation is primarily concerned with daemons, but the principle is the same; the key you're interested in is WatchPaths
, so searching for that might find something more like a tutorial).
If you go this route, you need to create a .plist
like the following, which runs the command /path/to/virus/scanner.sh /Junk/Downloads
whenever the /Junk/Downloads
directory is modified.
<?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>Label</key>
<string>localhost.clamav.clamscan</string>
<key>LowPriorityIO</key>
<true/>
<key>Nice</key>
<integer>1</integer>
<key>ProgramArguments</key>
<array>
<string>/path/to/virus/scanner.sh</string>
<string>/Junk/Downloads</string>
</array>
<key>WatchPaths</key>
<array>
<string>/Junk/Downloads</string>
</array>
</dict>
</plist>
Put that in $HOME/Library/LaunchAgents/foo.plist
, and the command launchctl load $HOME/Library/LaunchAgents/foo.plist
will start it going.