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 offline   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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
Use backslash in Applescript running a Bash Shell Script rebello95 Mac Programming 12 Nov 3, 2011 01:56 PM
Resolved: Applescript and lists Roadrun3r Mac Programming 6 Jun 5, 2011 06:20 AM
Applescript shell script won't run when display is sleeping BlueRevolution Mac Programming 6 Feb 19, 2011 03:11 AM
Browse for shell script applescript flashuni Mac Programming 1 Jul 9, 2008 09:31 PM
Shell Script / AppleScript - backing up FlashDisks? satans_banjo Mac Programming 0 Oct 9, 2006 09:44 AM


All times are GMT -5. The time now is 06:13 AM.

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

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