Skip to content

Instantly share code, notes, and snippets.

@halorgium
Forked from mkb/gist:1218376
Created September 16, 2011 05:24
Show Gist options
  • Save halorgium/1221268 to your computer and use it in GitHub Desktop.
Save halorgium/1221268 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby -wKU
@actions = Hash.new {|h,k| h[k] = []}
def tell_program(name, &block)
@actions['songstart'] << lambda do |*args|
IO.popen("osascript", "w") do |f|
f.puts %Q{
tell application "System Events"
if exists process "#{name}" then
tell application "#{name}"
#{block[*args]}
end tell
end if
end tell
}
end
end
end
def default_message(title, artist)
%Q|now playing \\"#{title}\\" by #{artist}|
end
tell_program "Adium" do |title, artist|
%Q{set status message of every account to "#{default_message title, artist}"}
end
tell_program "iChat" do |title, artist|
%Q{set status message to "#{default_message title, artist}"}
end
@actions['songfinish'] << lambda do |title, artist|
system("say", "just listened to #{title} by #{artist}")
end
event = ARGV.first
details = {}
$stdin.each_line do |line|
key, value = line.chomp.split('=', 2)
details.store(key, value)
end
@actions[event].each do |action|
action.call details['title'], details['artist']
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment