Inspired by Nat Pryce’s recent scrapheap challenge idea for a Name That Tune style game, and given I’ve been having so much fun with the Ruby OSA lately, I decided to implement my own solution using it to drive iTunes and I had a lot of fun in the process.
I started by grabbing a reference to iTunes:
%w(rubygems rbosa).each {|lib| require lib }
itunes = OSA.app(”iTunes”)
And then playing about with it until I found the right properties to look at and methods to call. As the game requires a constant stream of random tracks, I thought using the Party Shuffle feature of iTunes to would fit just right. The Party Shuffle is a special playlist that sits inside your library:
library = itunes.sources.find {|s| s.kind == OSA::ITunes::ESRC::LIBRARY }
party_shuffle = library.playlists.find {|p| p.special_kind == OSA::ITunes::ESPK::PARTY_SHUFFLE }
With that party_shuffle (an OSA::ITunes::Playlist object) at hand, it’s pretty easy to do the rest: playing, changing tracks and figuring out how to score each guess.
If you can grab the complete solution and make it into a nice little dashboard widget, I’ll be forever in debt!
BONUS UPDATE: I just finished refactoring a couple of things (namely, moving the monkey patching of OSA::ITunes away - it’s now in itunes.rb) and, in the process of doing so, Tune Fight was born!

Mistaeks I Hav Made | 05-Apr-07 at 6:08 pm | Permalink
Scrapheap Challenge at SPA2007, part 3: Name that Tune…
The second challenge in the SPA 2007 Scrapheap Challenge workshop was: A Christmas Quiz Game. I want a quiz game to play at Christmas. The most important feature is that I don’t want to have to prepare the quiz beforehand…….
Laurent Sansonetti | 10-Apr-07 at 5:42 pm | Permalink
Hey Carlos,
This is a very nice RubyOSA script! Would you be willing to contribute it as an official RubyOSA example? If yes, please drop me a message: lrz at chopine dot be.
Thanks,
Laurent