Compressor post-processing with AppleScript
Compressor is a file conversion utility included with Apple's Final Cut Pro. It's very handy. There's an option in the preset inspector to run an AppleScript upon completion ("Execute action on output"). While that can be incredibly handy, I was unable to find any sample code on how to actually make that work.
After some experimenting I found what I was looking for. As with many things the answer was quite simple; the full name (including path) of the file is sent to the script as an "open" argument, essentially as if it were sent via the Unix command line. Another trick - the script must be saved as an application, not just a script. Here's all you need:
on open (thefiles)
--There should only be one file, but just in case send it through a loop
repeat with thefile in thefiles
DoSomethingWith(thefile)
end repeat
end open
Really, that's it. Here's a script I threw together to upload a completed file to an FTP site, using Fetch. This should be easily adaptable to other FTP utilities like Transmit or Interarchy. One could also use the Unix command CURL. One could easily add other conversions, email notification through a regular email program, etc.
Just copy/paste this into Script Editor, save it as an application, and attach it to your Compressor preset using the Applescript checkbox mentioned above. Voila. If you have any questions or feedback (or want to hire me to write a script for you :-> ) please drop me a note.
on open (thefiles)
--There should only be one file, but just in case send it through a loop
repeat with thefile in thefiles
FetchUploadFile(thefile)
end repeat
end open
on FetchUploadFile(thefile)
set themode to "ftp" --either ftp or sftp
set theusername to "yourusername"
set thepassword to "yourpassword"
set theaddress to "ftp.yourwebsite.com"
set thepath to "public_html/yourpath/"
set theurl to themode & "://" & theusername & ":" & thepassword & "@" & theaddress & "/" & thepath
with timeout of 60000 seconds
try
tell application "Fetch"
activate
put into url (theurl) item thefile
end tell
on error
display dialog "error uploading " & thefile
end try
end timeout
end FetchUploadFile
on run
display dialog "This is meant to be called from Compressor."
end run
Enjoy!
|