Using Applescript with PERL

Ultram Without Prescription Nexium No Prescription Zelnorm For Sale Antabuse Generic Buy Amoxil Online Prednisone Without Prescription Penisole No Prescription Propecia For Sale Amoxil Generic Buy Clarinex Online

One of the great advantages of OS X is that you can control applications using Applescript. There is a command line version of calling applescript called osascript. The really cool thing is being able to use this command inside of another script such as a perl script or a shell script. One of the things I do is use PERL to read through a directory of files and do something with them using Applescript.

First create a subroutine using PERL:

# Subroutine to actually run a bit of AppleScript.
sub AppleScript {
my($script) = shift @_;

print “$script\n”;
system(qq|/usr/bin/osascript -e ‘$script’|);
}

Then whatever applescript you put into $script will be run by the osascript command. It is nice to do it this way, because now you can set variables within the Applescript commands. The variables get populated in perl before the osascript command is called.

Here is a distiller script that opens a ps file and distills it to the location set in $pdfOutMac.

$script = qq|
tell application “$DISTILLER_PATH”

activate
open (”$PS_MAC” as alias) destination (”$pdfOutMac” as alias) wait true

end tell
|;

Now call the perl subroutine like this:

AppleScript($script);

and you will launch the applescript.

Comments are closed.