AppleScript and do shell script

Random chit-chat and anything that doesn't belong elsewhere
Post Reply
refulgentis
Bright Spark User
Posts: 342
Joined: Mon Apr 14, 2008 5:08 am

AppleScript and do shell script

Post by refulgentis »

I have a shell script set up as a folder action, to automatically take any files added to the folder and convert them. It works properly, but my one problem is that while the script is running, any files added to the folder are ignored, because its busy running "do shell script (convert)".

Anyone have any suggestions on how to handle this?

iJoel
Regular User
Posts: 124
Joined: Sat Dec 20, 2008 7:25 am

Re: AppleScript and do shell script

Post by iJoel »

Run the "do shell script" in the background.
& end the script. That way the HandbrakeCLI will still be running,
but your script execution will be done.

Then if another file get's added to the list your Folder Action script will execute.
Even though there's already a file encoding with HandbrakeCLI.

Then at the beginning of your folder action script,
you check to see if the "System" currently has HandbrakeCLI running,
IF it does you can DELAY your script every, say 20 minutes and after
the DELAY you check again to see if HandbrakeCLI is still running,
and if it isn't then you "do shell script" your next file.

Granted, if you didn't care about 2 HandbrakeCLIs running in the background you
could skip the System check.


& also, there's a lot of different ways you could handle this.
The above example was the easiest way I could think of from the top of my head.
But how you really want to do it comes down to priorities. You could set up a cron-tab
for example, and have your folder action spit our a queue that the cron-tab could read
and execute for you every x minutes/hours.

Oh, and if you need code examples for any of that, I could show you,
but I didn't know how proficient you are with applescript ^__^

refulgentis
Bright Spark User
Posts: 342
Joined: Mon Apr 14, 2008 5:08 am

Re: AppleScript and do shell script

Post by refulgentis »

iJoel wrote:Run the "do shell script" in the background.
& end the script. That way the HandbrakeCLI will still be running,
but your script execution will be done.

Then if another file get's added to the list your Folder Action script will execute.
Even though there's already a file encoding with HandbrakeCLI.

Then at the beginning of your folder action script,
you check to see if the "System" currently has HandbrakeCLI running,
IF it does you can DELAY your script every, say 20 minutes and after
the DELAY you check again to see if HandbrakeCLI is still running,
and if it isn't then you "do shell script" your next file.

Granted, if you didn't care about 2 HandbrakeCLIs running in the background you
could skip the System check.


& also, there's a lot of different ways you could handle this.
The above example was the easiest way I could think of from the top of my head.
But how you really want to do it comes down to priorities. You could set up a cron-tab
for example, and have your folder action spit our a queue that the cron-tab could read
and execute for you every x minutes/hours.

Oh, and if you need code examples for any of that, I could show you,
but I didn't know how proficient you are with applescript ^__^
I'm rapidly becoming very good with Applescript...my best area is shell scripting. I'm trying to think of a way to get a queue running by writing queue.txt to Application Support, and having the shell script for encoding check queue.txt to see if anything was added while it's done. Actually...that's a solution. In the file parsing code If handbrakecli is running, append to queue.txt, if it isn't running, run shell script in background. Add work to end of shell script which reads queue.txt, uses the first line to encode, and rewrites queue.txt with the remaining lines. I have to brainstorm more, unfortunately work and school get in the way. :P

iJoel
Regular User
Posts: 124
Joined: Sat Dec 20, 2008 7:25 am

Re: AppleScript and do shell script

Post by iJoel »

Sounds like you got it ^__^.

then
do shell script "handbrakeCLI -i dvd -o file > /dev/null 2> ~/output.txt"
should solve all your problems ;P.

monkeyangst
Posts: 1
Joined: Fri Mar 13, 2009 4:54 pm

Re: AppleScript and do shell script

Post by monkeyangst »

Any chance you'd be interested in posting the script you came up with? I'm trying to achieve the same result, but haven't been able to figure it out.

refulgentis
Bright Spark User
Posts: 342
Joined: Mon Apr 14, 2008 5:08 am

Re: AppleScript and do shell script

Post by refulgentis »

monkeyangst wrote:Any chance you'd be interested in posting the script you came up with? I'm trying to achieve the same result, but haven't been able to figure it out.
I'd refer you to http://code.google.com/p/videoengine/ for an about 95% complete, stable, easy to use implementation. http://code.google.com/p/videoengine/so ... trunk/SCPT has the scripts in it -- convert - video to mp4 using Breakfast is a folder action that accepts files added to the folder and writes them to queue.txt and starts engine.sh in the background, which then reads through queue.txt encoding.

iJoel
Regular User
Posts: 124
Joined: Sat Dec 20, 2008 7:25 am

Re: AppleScript and do shell script

Post by iJoel »

Nice work.
Love the name haha.
I made something very similar in the app I'm making,
but you know what I'm really unsure of (at least in the app I made),
whether I should specify an average bitrate, or CQ.

I mean DVD are somewhat consistent, but videos from online really arn't.
What do you set for video settings? Just the normal universal preset?
Just curious ;P.

refulgentis
Bright Spark User
Posts: 342
Joined: Mon Apr 14, 2008 5:08 am

Re: AppleScript and do shell script

Post by refulgentis »

my sources are pretty consistent -- I use a version of dynaflash's advanced AppleTV settings (soon to become the AppleTV preset), which is basically bf=3:ref=3:8x8dct=1:cabac=1, and crf=23 because my sources are HD

iJoel
Regular User
Posts: 124
Joined: Sat Dec 20, 2008 7:25 am

Re: AppleScript and do shell script

Post by iJoel »

refulgentis wrote:my sources are pretty consistent -- I use a version of dynaflash's advanced AppleTV settings (soon to become the AppleTV preset), which is basically bf=3:ref=3:8x8dct=1:cabac=1, and crf=23 because my sources are HD
Do the files you encode come out much larger than the original?
& haha, I didn't even know that the ATV could handle all that ;P.

Post Reply