Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

refulgentis

macrumors regular
Original poster
May 14, 2006
114
0
Hi,
I have a rather lengthy script I'm using as a folder action for automatic video conversion, essentially it boils down to "add (extension) to this folder? ok, pass it to a shell script and convert."

This works fine, except for one thing -- since the folder action is still running while it's running "do shell script (conversion line)", any files added during the conversion are ignored. This is unacceptable, because video conversion takes so darn long.

Any suggestions?

James
 

HiRez

macrumors 603
Jan 6, 2004
6,265
2,630
Western US
You could have your script maintain a queue of files to be processed. Store the original list of files and then, after each conversion, drop the current (just converted) file off the list, get a list of the current contents of the drop folder and compare that to the original list, adding into the queue the new ones. Kind of a PITA but it should work.

Alternately, you could launch each conversion process as a background process, allowing the AppleScript to immediately return and become available for relaunching. The only problem there is that all those processes will be run simultaneously instead of one at a time, which could cause problems with CPU starvation or low memory if you drop a lot of files at once. You can launch a "do shell script" as background by appending " &> /dev/null &" to the end of your command-line section (note the space between this and your original command):

Code:
do shell script "ftp blah blah blah &> /dev/null &"
 

refulgentis

macrumors regular
Original poster
May 14, 2006
114
0
You could have your script maintain a queue of files to be processed. Store the original list of files and then, after each conversion, drop the current (just converted) file off the list, get a list of the current contents of the drop folder and compare that to the original list, adding into the queue the new ones. Kind of a PITA but it should work.
Yeah...I'm brainstorming ways to handle a queue like that. It'll take a significant rewrite to separate the file parsing code from the handing off for conversion code, and then to do the queue parsing on top...but hey, its just a 100 line applescript. :p

Alternately, you could launch each conversion process as a background process, allowing the AppleScript to immediately return and become available for relaunching. The only problem there is that all those processes will be run simultaneously instead of one at a time, which could cause problems with CPU starvation or low memory if you drop a lot of files at once. You can launch a "do shell script" as background by appending " &> /dev/null &" to the end of your command-line section (note the space between this and your original command):

Code:
do shell script "ftp blah blah blah &> /dev/null &"

Ahh I don't know why I didn't think of that. Thanks!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.