Leopard loves Ruby

Posted by crayz

The following uses ruby-growl and Apple's RubyOSA (think AppleScript for Ruby) to connect to iTunes and push the current track(if there is one) to its end, and pop-up a nice notification that it did. It's a slightly silly use, but I've always wanted a quick way to skip to the end of the current song while still bumping it's playcount(just hitting "next track" in iTunes won't increment your playcount of the current one, even though you just listened to 75% of it)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
GROWL_PASS = "zzzzz"

require 'rubygems'
require 'rbosa'
require 'ruby-growl'

def growl_notify(message)
  growl = Growl.new "localhost", "ruby-growl", ["itunes-ruby"], nil, GROWL_PASS
  growl.notify "itunes-ruby", "iTunes / ruby", message
end

itunes = OSA.app('iTunes')
if(current_track = itunes.current_track.get rescue false)
  track_name = current_track.name
  itunes.player_position = current_track.finish
  growl_notify "track '#{track_name}' ended"
else
  growl_notify "no track currently playing"
end

(sorry about the fugly syntax hilighting)

Comments

Leave a response

  1. goofy girlOctober 30, 2007 @ 04:26 PM

    Now the count for road to perdition… 10 MILLION :D