An AppleScript to copy lyrics from iTunes' songs

May 25, '06 07:30:03AM

Contributed by: juanfal

I have not had any luck finding any Terminal or GUI applications that could get lyrics from MP3 ID3v2 tagged files. The only way I've found is to go into the info dialog (in iTunes) and copy the text there.

If you're looking for lyrics to several songs, or want and easier way to do this simple and useful task -- I love to do this because while I listen to the song, I can read the lyrics and control iTunes or leave it behind other applications -- you can use this AppleScript:

tell application "iTunes"
  set these_tracks to the selection of browser window 1
  
  set the track_count to the count of these_tracks
  display dialog "Copying lyrics of " & (track_count as string) & ¬
    " tracks." buttons {"Cancel", "Copy"} default button 2
  if the button returned of the result is not "Copy" then
    return
  end if
  set the item_counter to 0
  set letras to ""
  repeat with this_track in these_tracks
    if letras is not "" then
      set letras to letras & return & return
    end if
    
    set letras to letras & "==> " & the name of this_track & return & the lyrics of this_track & return
    
  end repeat
  set the clipboard to letras
  
end tell

As I have said, I'm not aware of a Terminal tool that can extract this text (mpg123 can't. However, it could be yet more interesting to call this script from there, and build a text file with the result. The problem is that you need to start iTunes (from Terminal) and look for songs by their names, and this can be very slow and prone to errors.

[robg adds: This script worked as described, though I only tested it directly from AppleScript.]

Comments (4)


Mac OS X Hints
http://hints.macworld.com/article.php?story=2006052104465643