Slash Boxes
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 ]

cwest (1514)

  (email not shown publicly)
AOL IM: caseyrwest (Add Buddy, Send Message)

Perl geek.

Journal of cwest (1514)

Wednesday September 25, 2002
01:58 PM

Control iTunes from the Command Line

[ #8011 ]

Many thanks to brian d foy for making me more productive. No need to touch the mouse or switch applications or maximize iTunes. Now I can switch the song or replay without pain.


if ( my $action = shift ) {
    fork and exit;
    require Mac::iTunes;
    Mac::iTunes->controller->$action( @ARGV );
} else {
    print "Usage: $0 action [args]\n";

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • I've been doing this in iTunes since before there WAS an iTunes (that is, in SoundJam, its predecessor), from ircle. I have /next, /play, /stop, /previous, /np, etc., all as small compiled AppleScripts, which is quite a bit faster than compiling AppleScript on the fly.

    brian may wish to look into including compiled AppleScripts with the module, or, better yet, using osacompile to write out scripts to a directory during make, or on demand. Something like:

    my $folder = dirname($INC{'Mac/');
    my $scri

    • Yeah, Mac::iTunes is incredibly slow, thus my first ever direct use of fork in Perl code.
      Casey West
      • i'm not too worried about speed at the moment. once Mac::iTunes::AppleScript loads, things are faster than i expected. if you use it for only one command then dump out of the script, well, that's what you get.

        i'm also working on an iTunes command server so a daemon process accepts commands.

        i'll check out the compiled stuff later. right now i'm still wrestling with iTunes to make it do what it advertises. :)
        • Hrm.. POE::Component::(Client|Server)::iTunes

          I'm feeling the itch...

          Casey West
        • hey, i bet you're using the publically available Mac::iTunes, which is super slow because it doesn't use Mac::AppleScript for most things since Dan didn't have a way to return values at that time.

          next week i'll release another version that gets rid all of the system calls. it's broken in some pretty heinous ways right now, but you can also scout around SourceForge if you really want to be brave. (the ticket to entry is actually finding it on SourceForge and figuring out anon CVS :)
    • Whoa. What we need is Inline::AppleScript. Ingy, please rescue us!
      • Randal L. Schwartz
      • Stonehenge