Displaying lyrics

I’ve been learning Spanish for a little while, and the other day I put on an album I forgot I had - Tres Cosas by Juana Molinahttp://www.youtube.com/watch?v=s9O_kQxDddo - and the lyrics are almost all in Spanish.

To help me learn, and appreciate the music better, I got hold of some of the lyrics, put them in the tracks’ lyrics field and then wrote this little script using appscript (the better version of Applescript) to display the lyrics to me via growl.

# encoding: UTF-8

require 'appscript'
require "growl"

app = Appscript.app.by_name "iTunes"
NAME = "lyrics"

IMG = File.join( File.dirname(__FILE__), "musical_note.gif" )
lyrics = app.current_track.lyrics.get.force_encoding('UTF-8')

unless lyrics.nil? || lyrics.empty?
  lines = lyrics.split "\r"
  chunks = []
  chunk = "" 

  lines.each_with_index do |line, index|
    if chunk.length + line.length <= 100
      chunk += "#{line}\n" 
      (chunks << chunk) && chunk = "" if lines[index + 1].nil? 
      ((chunks << chunk) << "#{line}\n") && chunk = ""

  chunks.each do |c|
    sleep 0.4
    Growl.notify do |n|
      n.name = NAME
      n.message = c
      n.sticky = true
  Growl.notify do |n|
    n.name = NAME
    n.message = "no lyrics"
    n.image = IMG
    puts "no lyrics"

You’ll have to set Growl to how you like it best, but I have mine set to “smoke” from the top right. I might do a bit more to it soon, but this is enough for now :)

Update: I made a mistake, some lines were getting cut out. I also noticed that Growl hasn’t improved with the number of notifications it can get so I lengthened the time between them and now all should appear!