Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Feb 7, 2009, 12:05 PM   #1
refulgentis
macrumors regular
 
Join Date: May 2006
AppleScript and do shell script

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
refulgentis is offline   0 Reply With Quote
Old Feb 7, 2009, 12:58 PM   #2
HiRez
macrumors 601
 
HiRez's Avatar
 
Join Date: Jan 2004
Location: 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 &"
__________________
Go outside, the graphics are amazing!
HiRez is online now   0 Reply With Quote
Old Feb 7, 2009, 01:01 PM   #3
refulgentis
Thread Starter
macrumors regular
 
Join Date: May 2006
Quote:
Originally Posted by HiRez View Post
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

Quote:
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!
refulgentis is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Apple script batch shell script prramesh Mac Programming 5 Sep 15, 2013 03:35 AM
AudioScope.sh shell script... wisecracker MacBook Pro 0 Jul 31, 2013 01:31 PM
Shell Script to Sync iPhoto ajbudis Mac Programming 0 Jun 30, 2013 12:52 PM
Anyone know how to use AppleScript or shell-script? gba2000 Mac Applications and Mac App Store 0 Apr 23, 2013 11:14 AM
Need help with a shell script thatgreenvw Mac Programming 1 Nov 30, 2012 07:55 AM

Forum Jump

All times are GMT -5. The time now is 09:09 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC