Jan Rychter: blog (electronics, programming, technology)

Folder actions on Mac OS X: usable now?

2009-10-01

AppleScript release notes for Snow Leopard (Mac OS 10.5.6):
Folder Actions now attempts to delay calling “files added” actions on files until they are done being copied. Previous versions called “files added” actions on new files as soon as they appeared in the file system. This was a problem for files that were being copied into place: if the file was sufficiently large or coming over a slow server link, the file might appear several seconds before it was done being copied, and running the folder action before it finished copying would behave badly. Folder Actions now watches if the file is changing size: if it stays the same size for more than three seconds, it is deemed “done”, and the action is called.

My experience with folder actions was that they are one big race condition waiting to bite you. It’s something all the tutorials conveniently glossed over. I kept wondering why Apple kept them if they are so obviously unreliable.

Hopefully that change, while far from correct, will make them usable.


Comments

What if I want to configure this delay? For example, maybe I know that the file is small and written locally, so a 100 ms delay would be plenty. Ideally I can modify this on a per-folder basis.

Marcos2011-09-13

Marcos: any solution based on delay is wrong.

What if your computer is under load and writing to the file takes longer than 100ms? What if you suspend your computer in the middle of a write operation? There are a million things that could happen and basing folder actions on delays is just plain wrong.

Jan Rychter2011-09-18