Mac::Stuff

| | Comments (0)
I've had several requests before to make OSA scripts accept arguments. For example, in Mac::OSA::Simple, you can do, for a saved script:

tell application "iTunes"
    play
end tell

This:

my $play = load_osa_script('itunes_play');
$play->execute;

But what if you want to play a specific track? You don't want to recompile your script, because that is inefficient (it can take awhile to compile an AppleScript, plus you don't want little AppleScripts all over the place).

So I mostly have it worked out that you will be able to pass arguments to your compiled AppleScript. What the code will look like, with the AppleScript:

on «event abcd1234» (trackname)
    tell application "iTunes"
        play (first track of library playlist 1 whose name is trackname)
    end tell
end «event abcd1234»

and the Perl code:

my $play = load_osa_script('itunes_play');
$play->call('abcd ', '1234', 'Pearls Before Swine');

And on the command line or whatever, you could have simply:

% iplay "Pearls Before Swine"

That's the plan, anyway. I have it working (the low-level stuff). I found a bug in Mac::OSA::OSADoEvent where the reply event was not getting filled out, so it was failing, so it will require a newer Mac::Carbon. I'll do it sometime this summer.

And yes, I know, Mac::Carbon is still slow when loading the extensions, in some cases. I'll work on that this summer, too. :-)

Now Playing: Most Likely You Go Your Way And I'll Go Mine - Bob Dylan (Biograph)

use.perl.org

Leave a comment

<pudge/*> (pronounced "PudgeGlob") is thousands of posts over many years by Pudge.

"It is the common fate of the indolent to see their rights become a prey to the active. The condition upon which God hath given liberty to man is eternal vigilance; which condition if he break, servitude is at once the consequence of his crime and the punishment of his guilt."

About this Entry

This page contains a single entry by pudge published on June 4, 2003 10:18 AM.

All Over Again was the previous entry in this site.

Calling AppleScripts With Arguments is the next entry in this site.

Find recent content on the main index or look in the archives to find all content.