iTunes Veto: avoid those overplayed new songs
I listen to a stream of The Current almost all day, every day. I love this station, but I cringe every time they play that new Green Day song or when I hear Bono sing, well, anything. No longer! I’ve written a set of Ruby scripts that’ll let me veto away the ugliness so that I’ll never get nasty songs stuck in my head again.
I should point out that these scripts assume you’re running Mac OS X 10.5 with Developer Tools installed. Both scripts use the osx/cocoa library to interact with iTunes.
veto
the veto script pulls the track title that iTunes is currently streaming 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 background and looks for vetoes songs to appear the iTunes stream. When they do, it turns down the volume and spares your ears. When the vetoed track is done, the volume goes back up. Note: this should return the volume to it’s previous setting, but the instance variable kept breaking, 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 Quicksilver trigger to run the veto script. What’s up now, Bono?
Comment on this post