PDA

View Full Version : Anyone good with Applescript and Perl?




PuNkErX
Oct 13, 2006, 05:08 PM
Hey,

I am having a few issues with a script I'm making. This script will eventually, look into a folder on the server, grab one *.mov file, move it to the local harddrive, open up quicktime, encode the movie with settings from a file, then move the encoded *.mov back into a new folder on the server.

Sounds easy right? lol

I've been getting little bits and pieces down, I don't know perl and applescript well enough to do a decent job, but here is my perl script.


#!/usr/bin/perl -w

use Mac::AppleScript 'RunAppleScript';

my $source = $ARGV[0];
my @cmd = ("open", "$source");

system(@cmd) == 0
or die "System @cmd failed: $?";

# The Applescript that opens Quicktime to encode the movie in $ARGV[0]
# Throw it all into the $script variable

my $script =<<END;

tell application "QuickTime Player"
with timeout of (86400 * 2) seconds
if not (exists movie 1) then error "No movie file open."
if not (can export movie 1 as QuickTime movie) then error "Can't export movie."
export movie 1 to "movie.mov" as QuickTime movie using settings "VODSettings" with replacing

close movie 1
quit saving no

end timeout
end tell

END

RunAppleScript($script) or die "Did not work";
exit(0);


If you can read through the junk, basically the perl script runs, then opens a *.mov file that you specify. Once that is open, perl launches an applescript with RunAppleScript.

It runs now and encodes, but I was wondering if anyone knew how to take an argument from perl and put it into the applescript.

For example: I type: "./VODDuex.pl mymovie.mov
Then it runs, and instead of applescript creating the "movie.mov" file in the /, I can pass another argument like "./VODDuex.pl mymovie.mov finished.mov" and the script will run and create finished.mov as the final encoded movie.

I have been workin on and off of this problem for a while now, I must not know the right keywords to tell google, lol.

Any questions, ask away.

Thanks,



Eraserhead
Oct 14, 2006, 06:25 AM
First why not do the whole thing in Applescript? It might be slower but it seems like Applescript can do what you want.

Assuming Perl can access the command line then you can pass variables to Applescript by putting an on run{param1,param2} at the top of the applescript (and an end run at the end) whether that will allow you to access the applescript direct from perl I'm not sure, as I don't know perl at all.

PuNkErX
Oct 14, 2006, 10:25 AM
Hey,

Thanks for the reply. I thought about using Applescript for the whole thing, which I may end up doing anyway. I was just dinking around playing with using both.

How would I put in the part in the Applescript about automatically searching a folder and it's subfolders for any .mov file, then copying it to the local machine, then copying it back into a different folder?

Eraserhead
Oct 14, 2006, 11:27 AM
Hey,

Thanks for the reply. I thought about using Applescript for the whole thing, which I may end up doing anyway. I was just dinking around playing with using both.

How would I put in the part in the Applescript about automatically searching a folder and it's subfolders for any .mov file, then copying it to the local machine, then copying it back into a different folder?

The automatic bit, I'm not sure about, you can search a folder with code similar to what is below, the file action code will need some editing to get it to do what you want.

set theFolder to "Macintosh HD:Applications:" --the starting folder
my searchTheFolder(theFolder)

on searchTheFolder(theFolder)
tell application "Finder"
set theFolderList to every folder of folder theFolder
set theFileList to every file of folder theFolder whose name ends with ".mov"
end tell
set i to 1
repeat the count of theFileList times
--do what you want with the files
my fileAction(item i of theFileList as string)
set i to i + 1
end repeat
set theFileList to null --so it doesn't use to much memory and run slowly
set i to 1
repeat the count of theFolderList times --so it repeats the subfolders
my searchTheFolder(item i of theFolderList as string) --converting the folder to a string for processing.
set i to i + 1
end repeat
set theFolderList to null --to reduce memory usage
set theFolder to null
end searchTheFolder
on fileAction(fileLocation)
tell application "Finder"
set theName to the name of fileLocation
copy fileLocation to folder "Local Machine"
--process file
copy file ("Local Machine:" & theName) to folder "remote location:"
end tell
set theName to null --to reduce memory usage
set fileLocation to null
end fileAction