one more update. this is working as expected.
$_[1] is a known database_id from iTunes...
my $library = $itunes->obj( 'playlist' => '1' );
my $tracks = $library->obj( 'tracks' => whose( 'database_id',
'equals', "$_[1]" ));
if( $^E ) { $msg .= $^E; }
else
{
for my $track ( $tracks->get() )
{
$itunes->play( $track );
}
}
apparently "some track" in AppleScript can correspond to "tracks" with
Mac::Glue. since there is only one result, the syntax looks funky but
works. hopefully someone else learns something from this... =)
> $_[1] is a known database_id from iTunes...
>
[quoted text clipped - 15 lines]
> Mac::Glue. since there is only one result, the syntax looks funky but
> works. hopefully someone else learns something from this... =)
First off: the for loop is completely unnecessary. If you have only one
item, you can just do $tracks->play (no need to get, and no need to do
$itunes->play($track)). If you have more than one item, you'd want to break
out of the loop anyway: both $tracks->play and for ($tracks->get) { $_->play
} will end up trying to play multiple tracks immediately.
Second, in AppleScript, "some track" is the same as "any track", and it is
asking for one random element from a group. And this is where AppleScript
hides some details that Mac::Glue does not. What is actually going on is
AppleScript is converting "some track whose ..." to "some track of tracks
whose ...". For example, your code is equivalent to the longer form:
some track of (tracks of library playlist 1
whose database ID is x)
And this is the literal Mac::Glue translation (note that gAny is used for
the synonymous some/any):
my $track = $itunes->obj(
track => gAny(),
tracks => whose(database_id => equals => $x),
playlist => 1
);
But since we can only get one result (as database_id has to be unique), we
can just get $tracks, as in AppleScript, you can also do:
tracks of library playlist 1 whose database ID is x
And as you found out in Mac::Glue, you can do:
my $track = $itunes->obj(
tracks => whose(database_id => equals => $x),
playlist => 1
);
So pulling this all together, I'd do it like this:
#!/usr/bin/perl
use warnings;
use strict;
use Mac::Glue ':all';
my $itunes = new Mac::Glue 'iTunes';
my $id = 45;
my $track = $itunes->obj(
tracks => whose(database_id => equals => $id),
playlist => 1
);
$track->play;
__END__
I hope that helps a bit.
BTW, I posted a Name That Tune script using iTunes and Mac::Glue.
http://use.perl.org/~pudge/journal/19985

Signature
Chris Nandor pudge@pobox.com http://pudge.net/
Open Source Development Network pudge@osdn.com http://osdn.com/
Brian Pink - 27 Jul 2004 22:33 GMT
chris,
thanks for the enlightenment. it was one of those situations where i
knew there had to be something better, but just wasn't sure what it
was. =)
- brian