Unreliable Folder Action

automatorfolder-action

I have a folder on my Computer, "Markdown Source" with a folder action applied to it through Automator. The folder action applies a shell script, and then writes output to a different folder, "Markdown Output" (no bonus points for guessing what the script might be).

The problem is that sometimes when I save a file to the "Markdown Source" the script runs, and creates the file in "Markdown Output", but sometimes it does not. This problem seems to happen most frequently if I re-add a file to the folder than has previously been in the folder but was subsequently moved elsewhere.

Does anyone know if there is a way to change how often Folder Actions look for new input, to manually force Folder Actions to run, or some other way to be sure that all the items in my Markdown Source directory get processed?

Best Answer

In my and others' experience, Folder Actions are unreliable, especially with large numbers of changes. So the problem you're facing is not specific to your system, but a rather common one.

I suggest you rewrite your script into one that receives a folder as input, and performs the Markdown transformation on all files within. Have it trigger automatically whenever a file is written to by a launchd job, with the parent folder specified in the WatchPaths rule.

Since most programs on OS X perform atomic saves and thereby replace the previous file instead of simply modifying its contents, the folder will also be updated and the job will be triggered reliably.

Markdown transformation also shouldn't be too time consuming, and you can always ensure only to transform files using your script that were changed in the last X minutes.