iTunes Veto: avoid those overplayed new songs

I lis­ten to a stream of The Cur­rent almost all day, every day. I love this sta­tion, but I cringe every time they play that new Green Day song or when I hear Bono sing, well, any­thing. No longer! I’ve writ­ten a set of Ruby scripts that’ll let me veto away the ugli­ness so that I’ll never get nasty songs stuck in my head again.

I should point out that these scripts assume you’re run­ning Mac OS X 10.5 with Devel­oper Tools installed. Both scripts use the osx/cocoa library to inter­act with iTunes.

veto

the veto script pulls the track title that iTunes is cur­rently stream­ing and appends it to ~/.itunes_vetoes_songs.

#!/usr/bin/env ruby -w

require 'osx/cocoa'
include OSX
OSX.require_framework 'ScriptingBridge'

itunes = SBApplication.applicationWithBundleIdentifier_("com.apple.iTunes")
`echo "#{itunes.currentStreamTitle}" >> ~/.itunes_vetoed_songs`

veto_watcher

veto_watcher runs in the back­ground and looks for vetoes songs to appear the iTunes stream. When they do, it turns down the vol­ume and spares your ears. When the vetoed track is done, the vol­ume goes back up. Note: this should return the vol­ume to it’s pre­vi­ous set­ting, but the instance vari­able kept break­ing, so it just goes back up to 100%—careful!

#!/usr/bin/env ruby -w

# start a new thread
pid = fork do

  require 'osx/cocoa'
  include OSX
  OSX.require_framework 'ScriptingBridge'

  @itunes = SBApplication.applicationWithBundleIdentifier_("com.apple.iTunes")

  def itunes_is_running?
    return !`ps -A -o comm | grep iTunes.app`.empty?
  end

  def mute
    @itunes.soundVolume = 0 if @itunes.soundVolume > 0
  end

  def unmute
    @itunes.soundVolume = 100 if @itunes.soundVolume == 0
  end

  def check_for_veto
    vetoes = `cat ~/.itunes_vetoed_songs`.split("\n")

    if vetoes.index(@itunes.currentStreamTitle)
      mute
    elsif @itunes.soundVolume == 0
      unmute
    end
  end

  # main loop: check for a veto every 5 seconds
  loop do
    check_for_veto if itunes_is_running?
    sleep(5)
  end

end

Process.detach(pid)

I have the veto_watcher script start up when I log in and I’ve set up a Quick­sil­ver trig­ger to run the veto script. What’s up now, Bono?

Comment on this post

You may use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>