Search for Lyrics on Google

Use info from the current or selected track to search for lyrics pages via Google in Safari.

There are tons of lyrics sites on the Web that are ready to provide you with the words to your favorite songs. This hack Googles for the lyrics of the currently playing or selected song in iTunes. You’ll be singing along by the second verse.

The Code

This script gets the name and artist of the currently playing track (or, if no track is playing, the selected track), tidies up the text, and incorporates it into a URL that is then used by Safari to search Google for sites containing the lyrics of that particular track:

    -- base of the URL string, includes the term "lyrics"
    property baseURL : "http//www.google.com/search?q=lyrics+"

    tell application "iTunes"

      -- get a reference to playing or selected track
      if player state is not stopped then
        set theTrack to current track
      else if selection is not {} then
        set theTrack to (item 1 of selection)
      else
        display dialog "Nothing is playing or selected." buttons {"Cancel"} ¬
          default button 1 with icon 0
      end if

      -- get the name and artist and replace "bad" characters
      tell theTrack
        set nom to my fixChars(name)
        set art to my fixChars(artist)

      end tell

      -- assemble URL string, replace spaces with "+"
      set theURL to (baseURL & ¬ (my replace_chars((art & "+" & nom), " ", "+"))) as text my open_location(theURL) end tell on fixChars(a) set myDelims ...

Get iPod and iTunes Hacks now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.