Folder Actions only run once

I created an Applescript that prints a file using the unix command line with CUPS (ie lpr -P <> <>…). The script runs fine but only once. In order to get it to work again I have to run the Enable Folder Actions script from the MenuBar.

on adding folder items to this_folder after receiving these_items
	-- these_items will contain a list of file references to the added items 
	do shell script "lpr -P SC_740hUSBi /Users/pallotto/Documents/OS9Printer/*"
	do shell script "rm /Users/pallotto/Documents/OS9Printer/*"
end adding folder items to

If you open Process Viewer after the script’s first execution, is System Events still running? I ask because System Events handles folder actions and it’s possible that the first execution of the script might be causing System Events to crash silently.

– Rob

Sure enough, the System Events process disappears after running the script. Any ideas. I looked through some of he logs in the console but couldn’t find anything.

Obviously something about the script is causing a problem. One thing that I’ve found that is guaranteed to cause System Events to crash is to cancel a download in Safari (the crash is triggered by the folder action that’s attached to my download folder and this isn’t a silent crash).

How are the files arriving in the folder that has the folder action? If it takes more than a couple of seconds, it’s possible that the script is kicking in before the whole file is present. On my download folder script, I added a repeat loop that uses the Finder to check the size of new files until the size stops changing, signaling a completed download and allowing the script to proceed.

– Rob

One of the things I was most looking forward to in OSX AppleScript was the rock solid stability of Unix driving folder actions for AppleScript. Unfortunately, it seems to me this is never going to happen. I have had the exact same problem with Folder Actions only running once. I think that fundamentally there is a problem with the Folder Actions architecture in OSX because it still craps out just like it did in OS9! I wouldn’t rely on Folder Action events because they just don’t work. You’re much better off creating an agent program that periodically scans folders for dropped files. I mean, for Christ sake they didn’t even try to address the whole “folder has to be open crap”. Folder Actions – “Abandon all hope ye who enter here!”