Skip to content

Instantly share code, notes, and snippets.

@balinterdi
Forked from lackac/imstatus
Created March 19, 2010 13:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save balinterdi/337487 to your computer and use it in GitHub Desktop.
Save balinterdi/337487 to your computer and use it in GitHub Desktop.
#!/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 <lackac@icanscale.com>
# 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
status = IMStatus::STATUSES.detect do |s|
1.upto(s.length - 1) do |i|
ARGV[0] == s.slice(0..i)
end
end
if ARGV.length < 1 or not status
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