Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

pudge (1)

pudge
  (email not shown publicly)
http://pudge.net/
AOL IM: Crimethnk (Add Buddy, Send Message)

I run this joint, see?

Journal of pudge (1)

Monday November 17, 2003
04:07 PM

Stupid Mac::Glue Tricks

[ #15823 ]

I use this with XChat Aqua. Note that I create the objects outside the handler: XChat smartly caches the script, so the objects are created once. That, combined with only loading the modules once, significantly decreases the execution time, to nearly nil.

Also, I use IsRunning() to see if I am running iTunes locally; if so, it uses that, and if not, it uses the other box running in the house.

I had to install Mac::Glue etc. for the system perl, which I rarely use, but the plugin library is only compatible with that one. But I made the directory containing the glues a symlink to my local perl's (`sudo ln -s /usr/local/lib/perl5/site_perl/5.8.0/Mac/Glue/glues /Library/Perl/5.8.1/Mac/Glues/` or whatever). Those are just Storable + MLDBM, I don't need separate copies of them.

#!/usr/bin/perl
 
use strict;
use Mac::Apps::Launch;
use Mac::Glue;
 
my $itunes = new Mac::Glue 'iTunes';
 
my $track = $itunes->prop('current track');
 
my $name = $track->prop('name');
my $artist = $track->prop('artist');
my $album = $track->prop('album');
 
sub np {
    if (IsRunning($itunes->{ID})) {
        $itunes->ADDRESS;
    } else {
        $itunes->ADDRESS(eppc => iTunes => 'sweeney.local');
    }
 
    my @data = map { $_->get } ($name, $artist, $album);
    my $str = $data[0];
    return 0 unless $str;
    $str = "$str - $data[1]" if $data[1];
    $str = "$str ($data[2])" if $data[2];
    IRC::command("NP: $str");
    return 1;
}
 
IRC::register("np", "1.0", "", "");
IRC::add_command_handler("np", "np");

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.