Created
March 19, 2010 10:57
-
-
Save lackac/337420 to your computer and use it in GitHub Desktop.
Simple ruby script to set iChat/Adium/Skype status and status message
This file contains hidden or 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 | |
# | |
# Update iChat/Adium/Skype status | |
# | |
# USAGE: imstatus <online|available|offline|away|dnd|invisible> [message] | |
# (supports partial status identifiers like 'on' or 'aw') | |
# | |
# László Bácsi <[email protected]> | |
# http://github.com/lackac | |
class IMStatus | |
STATUSES = %w{online available offline away dnd invisible} | |
def initialize(status, message = nil) | |
@status = status | |
@message = message.gsub('"', '\\"') unless message.nil? | |
end | |
def status(client) | |
if (client == :ichat or client == :adium) and @status == "dnd" | |
"away" | |
elsif (client == :ichat or client == :adium) and @status == "online" | |
"available" | |
elsif client == :skype and @status == "available" | |
"online" | |
else | |
@status | |
end | |
end | |
def message(client) | |
if @message.nil? and (client == :ichat or client == :adium) and @status == "dnd" | |
"Do not disturb" | |
else | |
@message | |
end | |
end | |
def ichat_status | |
"set status to #{status(:ichat)}" | |
end | |
def ichat_message | |
if message = message(:ichat) | |
%{set status message to "#{message}"} | |
end | |
end | |
def adium_status | |
"go #{status(:adium)}" | |
end | |
def adium_message | |
if message = message(:adium) | |
%{set status message of every account to "#{message}"} | |
end | |
end | |
def adium_status_with_message | |
unless message = message(:adium) | |
adium_status | |
else | |
%{#{adium_status} with message "#{message}"} | |
end | |
end | |
def skype_status | |
%{send command "set userstatus #{status(:skype)}" script name "imstatus"} | |
end | |
def skype_message | |
if message = message(:skype) | |
%{send command "set profile mood_text #{message}" script name "imstatus"} | |
end | |
end | |
def applescript | |
%Q{ | |
tell application "System Events" | |
if exists process "iChat" then | |
tell application "iChat" | |
#{ichat_status} | |
#{ichat_message} | |
end tell | |
end if | |
if exists process "Adium" then | |
tell application "Adium" | |
#{adium_status_with_message} | |
end tell | |
end if | |
if exists process "Skype" then | |
tell application "Skype" | |
#{skype_status} | |
#{skype_message} | |
end tell | |
end if | |
end tell | |
} | |
end | |
def run_applescript | |
IO.popen("osascript", "w") { |f| f.puts(applescript) } | |
end | |
end | |
if __FILE__ == $PROGRAM_NAME | |
if ARGV.length < 1 or not status = IMStatus::STATUSES.detect {|s| s.start_with?(ARGV[0])} | |
puts <<-EOS | |
USAGE: #{File.basename($0)} <#{IMStatus::STATUSES.join("|")}> [message] | |
(supports partial status identifiers like 'on' or 'aw') | |
EOS | |
exit 1 | |
end | |
message = ARGV[1] | |
IMStatus.new(status, message).run_applescript | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment