Sleep * 4 + Think * 4 = Tired * 1, or: Perl vs. AppleScript

chaoticset on 2002-11-25T20:58:09

In other words, I didn't get a lot of sleep last night, I thought a whole bunch today, and between the two I'm pretty tired.

The question was raised: Could Perl do what AppleScript can? i.e., make the remote control application do what it's supposed to do, instead of the useless behavior it currently engages in? I'm sure there's a way to do it, I just don't know it yet. Perhaps if I get my hands dirty a little bit inside some OS X documentation, I can route around this oncoming AppleScript debacle.

Anyway, I'm just keeping track for myself here: Gotta figure out what Linux would be best for this place as a play server, gotta figure out how to make the remote app work properly, gotta figure out what I'm doing wrong in Matriarch. Gotta this, gotta that. Hell, at least I'm busy.

I'm actually mulling the notion of working here after my school-credit internship's over, asking if they want me for a few more months at the cover price or possibly as a volunteer. Right now I'm only sinking maybe ten physical hours a week, tops. I could do that without blinking, I suspect. My main concern would be gas money, but that seems to be handling itself right now.

Besides -- it's not like I wouldn't be hacking Perl on my own time anyway, and it would be good resume fodder.


Mac::Glue, DoAppleScript

pudge on 2002-11-26T14:52:52

First, there is DoAppleScript in Mac::Carbon (or RunAppleScript in Mac::AppleScript; the former has been around longer and allows you to retrieve error text in $@). You can just run AppleScript inside of Perl:
use MacPerl 'DoAppleScript';  # module named MacPerl, runs on Mac OS X anyway
my $name = DoAppleScript('tell app "iTunes" to get name of current track');
Second, there is Mac::Glue, which currently is being ported to Mac OS X. It allows you to use Perl syntax with an AppleScript vocabulary. It's been in use for many years on MacPerl and will rely on Mac::Carbon (once Mac::AppleEvents is ported to Mac::Carbon, which is in progress). It allows stuff like:
use Mac::Glue;
my $iTunes = new Mac::Glue 'iTunes'; # 'tell app "iTunes"
my $nameobj = $iTunes->obj(name => of => 'current_track');
my $name = $iTunes->get($nameobj);
And of course, you can call methods like play, stop, etc. The "glue" for an app is created with a simple droplet or command-line program.

I hope to have that working on Mac OS X in December, though if you want to get started now, it will run under MacPerl in Classic and control your native Mac OS X iTunes (Apple events between Classic and Mac OS X work very well).