O'Reilly logo

iPod and iTunes Hacks by Hadley Stern

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Hack #92. Search the iTunes Music Store for the Current Song

Search the iTunes Music Store using info from the currently playing track.

You can search the iTunes Music Store (iTMS) using the handy link arrows associated with each track in the library. But this AppleScript hack lets you search the iTMS for the currently playing song, even if it's playing from a stream.

The Code

The script gets tag info from the currently playing track and displays it in a listbox so the user can choose which tags to use as search criteria. The script then affixes the chosen data to a URL, which is sent to iTunes.

	-- get info from current track
	tell application "iTunes"
	  if player state is not stopped then
	    if class of current track is not URL track then
		  tell current track to set {alb, art, nom, com} to ¬
		    {album, artist, name, composer}
		else

		if current stream title is not "" then 
		  set {art, nom} to my text_to_list(current stream title, " - ")	
		  set {alb, com} to {"", ""}
        else 
		  display dialog "Can't get data from stream." buttons ¬ 
		    {"Cancel"} default button 1 with icon 0 giving up after 30 
		end if

	    end if	
	  else 
		display dialog "No track currently playing." buttons {"Cancel"} ¬ 
          default button 1 with icon 0 giving up after 30 
      end if 
	end tell

	-- build list to display in choose from list box 
	set theOptions to {"Song:" & tab & nom, "Artist:" & tab & art, ¬ "Album:" & tab & alb, "Composer:" & tab & com} -- display choose ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required