At 1:48 +0200 2004.06.29, Bart Lateur wrote:
>How do I launch an external application with parameters?

This is done via Apple events, as best I know.


>I've tried the following with Applescript, which works fine (it's
>supposed to launch Acrobat Distiller with a given PostScript file) but
>takes 10 to 20 seconds of freezing time (compiling the Applescript)
>before anything happens:

One thing you could do is use Mac::OSA::Simple to write a compiled
AppleScript, and then call it with parameters.  Much faster.

You could also do it with Mac::AppleEvents::Simple or Mac::Glue.

        use Mac::AppleEvents::Simple;
        use Mac::Files;
        use Mac::MoreFiles;

        my $app = $Application{'R*ch'};
        my $file = '/Users/pudge/bin/happening';

        do_event(qw(aevt odoc MACS), "'----':alis([EMAIL PROTECTED]@), 
usin:alis([EMAIL PROTECTED]@)",
                map NewAliasMinimal($_), $file, $app);

Or:

        use Mac::Glue;
        use Mac::MoreFiles;

        my $app = $Application{'R*ch'};
        my $file = '/Users/pudge/bin/happening';

        my $finder = new Mac::Glue 'Finder';
        $finder->obj(file => $file)->open(using => $finder->obj(file => $app));

(Technically, these two are not entirely analagous, because the latter uses
object specifier records to define a file, whereas the former uses alias,
but aliases are easier to do in the do_event() syntax, and I kept files for
the Glue syntax not because they are easier -- they are the same ease of
use -- but because the original used "file".)

And then there's Mac::OSA::Simple, which takes a little more work, but is
probably the fastest:

        use Mac::OSA::Simple;
        use Mac::Errors;

        my $app = 'R*ch';
        my $file = 'Bourque:Users:pudge:bin:happening';

        my $script = load_osa_script('/Users/pudge/Desktop/foo.scpt');
        $script->call(qw(abcd 1234), $file);

You need to have a compiled AppleScript pointed for the load_osa_script
call, which would be something like:

        on «event abcd1234» (filepath)
                tell application "Finder"
                        set this_app to get application file id "R*ch"
                        open file filepath using this_app
                end tell
        end

I prefer the Mac::Glue method, since it looks the best to me, but YMMV.
The OSA option is probably the fastest, since the script is already
compiled and ready to go, and just needs to be loaded.

Note that I mix Unix and Mac paths there, because I am running it on Mac OS
X, but AppleScript needs Mac paths.  I don't need Mac paths in the first
two examples because NewAliasMinimal creates a path-agnostic alias, and
Mac::Glue converts Unix paths to Mac paths for you.

-- 
Chris Nandor                      [EMAIL PROTECTED]    http://pudge.net/
Open Source Development Network    [EMAIL PROTECTED]     http://osdn.com/

Reply via email to