Thanks to Simon and Chris, I've got the Mac::Glue bug. I used to use a program to post journal entries that had iTunes support built in. Now that I use emacs, I'm at a loss, right? Wrong. Here is my program for getting an HTML version of the current playing track, not unlike what the article outlined.
Use Mac::Glue;
use Mac::Apps::Launch qw[IsRunning];
our $ITUNES = Mac::Glue->new( 'itunes' );
sub iTunes () { $ITUNES }
print get_track() || '';
sub get_track {
iTunes or return;
return unless IsRunning(iTunes->{ID});
if ( iTunes->prop('player_state')->get eq 'playing' ) {
my $track = iTunes->prop('current_track');
my ($name, $artist, $album) = map $track->prop($_)->get,
qw[name artist album];
my $output = "<p><em>Now Playing: $name";
$output .= " · $artist" if $artist;
$output .= " · $album" if $album;
return $output .= "</em></p>\n";
}
return;
}
And here is my emacs keybinding.
(global-set-key (kbd "C-c m")
(lambda () (interactive)
(shell-command-on-region
(region-beginning) (region-end)
"current_track.pl"
(current-buffer) t)))
http://www.perl.com/pub/a/2004/01/23/macglue.html
Now Playing: Overjoyed · Jars of Clay · Much Afraid
Posted from caseywest.com, comment here.