Hi,
I want to write a Folder Action script that will send an email when a file has arrived on our FTP site but only when it’s completely copied. I know I can put a repeat loop in to keep checking the file size and also check if the file is open for access but does anybody know what would happen if, I receive a file and my script enters its repeat loop and while its in the loop somebody else tries to upload a file to the same folder? would the second upload be ignored by my folder action because its already running?
Thanks,
Nik
Nik:
This sounds like a job for launchd. I don’t think Folder Actions will be resilient enough for you. Grab a copy of Lingon (http://lingon.sourceforge.net/) if you’re unfamiliar with launchd’s .plist syntax - it’s pretty handy for quick tests with launchd. Also, keep Terminal open to monitor stuff with launchctl.
Have fun!
Jim Neumann
BLUEFROG
PS: Craig Smith has an article on UnScripted about launchd too. Check it out!
Hey Jim,
I’ve not used launchd before but I’ll check it out.
Thanks for the advice!
Nik
Folder actions in Leopard now use launchd, so Lingon/etc. isn’t strictly necessary. It SHOULD only fire off once the file is completely copied. (The possible exception being if the transfer is terminated unexpectedly) You will probably want to test, but it seems to do so in my tests.
You don’t need to worry about multiple files, either. The folder action process will spawn for each file that’s added, there is no overlap. This is also a Leopard improvement.
As always, test and verify, but in my experience, all this stuff works just the way you want it to.
Interesting info. I know there’s a new Folder Actions Server daemon in Leopard but didn’t know it was tied into launchd. I’ll have to do some reading today. (I’m on a Tiger machine by day and a Leopard machine by night - (sounds like I’m a superhero :P)) so it’s nice to know both.
Thanks again for the heads up!
Jim