MacPerl::AppleScript 0.02 review

Download
by rbytes.net on

MacPerl::AppleScript is a Perl extension for easily accessing scriptable Apps. SYNOPSIS use MacPerl::AppleScript; # #

License: Perl Artistic License
File size: 13K
Developer: Wolfgang Kinkeldei
0 stars award from rbytes.net

MacPerl::AppleScript is a Perl extension for easily accessing scriptable Apps.

SYNOPSIS

use MacPerl::AppleScript;

#
# create Application Object
#
my $app = MacPerl::AppleScript->new("Application Name");

my $doc1 = $application->new("document 1");
my $doc2 = $application->new("document 2 of $app");

#
# directly execute Script in Application
# (auto-creates a tell "Application Name" block for you
#
$app->execute("some applescript command");
$app->execute(["some applescript command", "..." ... ]);
$app->execute("some applescript command", "..." ... );

#
# alternative way using a hashref
# script: script to get executed (string or array-ref)
# object: optional, object to be named in the "tell" block
# timeout: optional, timeout in seconds
#
$app->execute({
script => [...],
object => $doc1,
timeout => 10,
});


#
# calling functions
#
$app->open('POSIX path "/path/to/file" as alias');
$app->open($app->convert_path('/path/to/file','alias'));
$doc->close();
$app->close($doc1);

#
# string interpolation to Applescript Object Name
# gets 'application "Application Name"' for $application
# gets 'document 1 of application "Application Name"' for $doc1
#
my $ascript_appname = "$app";
my $ascript_docname = "$doc1";

$app->execute("close $doc1"); # cool :-)

#
# getting/setting properties
#
my $foo_property = $app->{foo};

my $foo_bar_prop = $doc1->{'foo bar'};
my $foo_bar_prop = $doc1->{foo_bar};

$app->{bar} = "any value";

$doc1->{'foo bar'} = [1,2,3,4];
$doc1->{foo_bar} = {a=>1, b=>2};

my %properties = %{$app};

This module is not written for being efficient. In fact it is really inefficient but hopefully easy to use.

As AppleScript (and its way of communicating to Applications) usually has some kind of latency. The creation of readable code is the most important goal when writing this Module.

Another reason for some kind of inefficiency results in the technical problem that AppleScript is a strongly typed language. Converting types back to Perl is easy. But the other direction is not always clear, as converting a scalar from Perl to AppleScript needs some guessing.

The parts of the code that deal with these problems do some tries with different AppleScript commands wrapped in try-blocks. So usually one of the expression works without errors. The same approach is made with hash keys that can contain spaces or underscores inside the key name.

This module assumes that all strings are correctly encoded in perl internal's coding sheme based on Unicode. During the conversion to AppleScript all characters inside strings that are not ascii-clean are converted to strange looking unicode-string constructing sequences. I tested a lot of character schemes including west- and mid-european languages as well as russian, greek and arabic with some applications without getting problems.

Requirements:
Perl

MacPerl::AppleScript 0.02 search tags