How robust are Folder Actions?

I have been working on my first fairly complicated folder action script. The script is running on a server to take automatically generated EPS files and upload them to an FTP site (using curl in the shell). The process that generates the EPS file also generates an XML file that does not need to be uploaded.

I have gotten my script to work fine when I drop files one by one into the folder, but I am having trouble with scripts in the production environment. For example, sometimes the EPS arrives a few seconds after the XML, but the script is now busy processing the XML file, and does not handle the EPS. Or if the EPS is very large, the script grabs the file and starts processing it before it has been fully saved. I am willing to adjust my scripts with checks to make sure the file size has not changed in x number of seconds to help with the file not fully saved problem, but that seems like it may make the problem of the script being busy with one file and not launching when the next file arrives even worse.

It seems like these are basic problems with using Folder Action scripts in a production environment and must have been solved, I would appreciate any help.

Thanks,

Don

Yours seems to be a fairly common problem with folder actions that must accept large groups of files. The usual advice here on the bbs is to abandon the FA, and run a stay-open script app with an idle handler in its place that ‘watches’ the target folder and operates on the EPS files that appear after their size stabilizes.

To wait for a folder to stabilize in size when a lot of stuff is added, I use this:

set myFolder to (choose folder) as alias -- the folder that's loading
-- initialize for the loop
set Size_1 to size of (info for myFolder) --get initial size
delay 3 --wait 3 seconds
set Size_2 to size of (info for myFolder) --get a newer size, perhaps bigger
-- repeat until done
repeat while Size_2 ≠ Size_1 --if they don't equal, loop until they do
	set Size_1 to Size_2 --new base size
	delay 3 --wait three seconds
	set Size_2 to size of (info for myFolder) --get a newer size
end repeat --once the sizes match, the download is done
-- Onward to the rest of the process

thanks, I will look into adapting this approach.

I read thru the FAQ and looked at a bunch of posts (there are so many great threads!), sorry if this is a common question.

Don

Not to worry about common question. If you have problems getting it going, post again by all means. You didn’t give quite enough info for me to formulate something as a skeleton to start with.