Disabling Chat Accounts At The End Of The Day
I always forget to turn off my chat accounts at work at the end of the day. Below is a script to take my accounts offline when it’s time to go home. This is for Ubuntu 10.10 using Empathy for my Jabber accounts.
#!/usr/bin/env ruby
require 'rubygems'
require 'dbus'
# Get the proper DBus session address
pid = nil
programs = %w( gnome-session )
programs.each do |program|
pid = `pidof -s #{program}`
break unless pid.nil?
end
# Fail if we can't find the pid
exit if pid.nil?
# Get the address
info = IO.readlines("/proc/#{pid.strip}/environ").first.split("\0")
info.reject! { |x| !x.include? 'DBUS_SESSION_BUS_ADDRESS' }
address = info.first.split('=', 2)[1]
# Set the address
ENV['DBUS_SESSION_BUS_ADDRESS'] = address
# Get the objects
bus = DBus::SessionBus.instance
service = bus.service('org.freedesktop.Telepathy.AccountManager')
service.introspect
account_manager = service.object('/org/freedesktop/Telepathy/AccountManager');
account_manager.introspect
iface = account_manager['com.nokia.AccountManager.Interface.Query']
accounts = iface.FindAccounts []
accounts.first.each do |account|
account_object = service.object(account);
account_object.introspect
account_iface = account_object['org.freedesktop.DBus.Properties']
account_iface.Set 'org.freedesktop.Telepathy.Account', 'RequestedPresence', ['(uss)', [1,'offline','']]
end
You’ll need the ruby-dbus gem to use this. I just placed it in a file and call it from a cron job. The script finds all of your accounts via D-Bus and and then sends them a new presence.
Update 2011-01-31: Added code to find the correct DBus Session Address, since the cron job does not have it.

