-
-
Save halorgium/1221268 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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