Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Mac OS X > Script to do an action when a movie file is finished saving?

Script to do an action when a movie file is finished saving?
Thread Tools
Mac Elite
Join Date: Oct 1999
Location: Montréal, Québec (Canada)
Status: Offline
Reply With Quote
Sep 16, 2013, 01:55 AM
 
Hi! I'm frequently converting iMovie files to .mkv and then upload them via FTP. This is time consuming and as I convert the file during the night, I often have to set an alarm in the middle of the night to begin the uploading process. Is there a way to do a script to detect when the file is finished converting? There's a folder action that triggers when a file is added to a folder but I'm not sure if it works if it try to upload it while it's only partially there.

Also, would there be a way to save directly from iMovie to .mkv without using DivX converter? That would save me a lot of time. thank you!
     
P
Moderator
Join Date: Apr 2000
Location: Gothenburg, Sweden
Status: Offline
Reply With Quote
Sep 16, 2013, 02:24 AM
 
You don't mention what video format you want to use inside the MKV, but if it can be done with Handbrake, you could use the terminal and something like
Code:
HandbrakeCLI -i /source/file -o /output/file && ftp -u username:password@path.to.server /output/file
The && thingy means "only proceed with the second command if the first succeeds".

EDIT: I should mention that if it is a multiuser machine, your ftp password is visible to any other user by simply using ps. This is obviously not a problem if you are the only user, though.
The new Mac Pro has up to 30 MB of cache inside the processor itself. That's more than the HD in my first Mac. Somehow I'm still running out of space.
     
Administrator
Join Date: Apr 2001
Location: San Antonio TX USA
Status: Offline
Reply With Quote
Sep 16, 2013, 05:36 AM
 
I'd never seen the "&&" operator before. Very useful bit there.

Can the Terminal command you provided be included in a script so that a list of source files could be converted and uploaded until the list is exhausted?

Glenn -----OTR/L, MOT, Tx
     
P
Moderator
Join Date: Apr 2000
Location: Gothenburg, Sweden
Status: Offline
Reply With Quote
Sep 16, 2013, 06:10 AM
 
Absolutely! The easiest way is to use the for command (I'm assuming bash or zsh here - csh/tcsh scripting is still considered harmful)

Code:
for FILE in file1 file2 file3 do HandbrakeCLI -i /source/$FILE -o /output/$FILE && ftp -u username:password@path.to.server /output/$FILE done
The && thing is originally a hack, but it's so useful that it has become standard to make the shell behave like that. A single ; means execute command 2 once command 1 finishes, no matter the result. || is the opposite of && - execute command 2 if command 1 fails. & means start executing command 2 as soon as command 1 has started (it executes independently and can finish before it), and | means execute command 2 using the output of command 1 as input.
The new Mac Pro has up to 30 MB of cache inside the processor itself. That's more than the HD in my first Mac. Somehow I'm still running out of space.
     
Addicted to MacNN
Join Date: Aug 2006
Location: God's Country
Status: Offline
Reply With Quote
Sep 16, 2013, 09:11 AM
 
That's pretty awesome. Do you have a link to a site or document explaining this (and possibly other, similarly useful syntax for Bash scripting)? I'll be adding that to my list of "things you should know by now".
     
P
Moderator
Join Date: Apr 2000
Location: Gothenburg, Sweden
Status: Offline
Reply With Quote
Sep 16, 2013, 10:49 AM
 
As I said, it's an old hack. What happens is this: && is logical AND. AND is true only if both the ingoing variables are true, so if the first process returns false, there is no reason to run the second, because you know that the result will be false. In the same way || is logical OR, and if the first process returns true, you don't have to run the second because you know that the result is true.

(Note that for process exit codes, 0 is true and anything else is false, completely the opposite of all other situations. There is a reason for this - if it's OK, then that's all you need, but if the process fails you want to know why it failed, so you need multiple error codes - but it's confusing enough that bash eventually implemented new special logical operators meant for if tests, reserving the && and || for the hacky use above).

As for documentation: This is where I look up things when I have to:

Advanced Bash-Scripting Guide
The new Mac Pro has up to 30 MB of cache inside the processor itself. That's more than the HD in my first Mac. Somehow I'm still running out of space.
     
   
Thread Tools
Forum Links
Forum 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
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 11:17 PM.
All contents of these forums © 1995-2013 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2013, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2