Tuesday, January 20, 2009

Go away in irssi whenever your screen is locked

My friends complain that I never set an away message. This is due to habit, and has a lot to do with the fact that irssi doesn't set me auto-away like my old clients used to.

But no more!

You will need this and this:

#! /usr/bin/env python

from dbus.mainloop.glib import DBusGMainLoop
import dbus
import socket
import gobject

DBusGMainLoop(set_as_default=True)

bus = dbus.SessionBus()

def handler(locked):
client = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
client.connect("/tmp/irssi_socket")
if locked:
client.send("command /away afk")
else:
client.send("command /away")
print client.recv(1024)
client.close()
bus.add_signal_receiver(handler, dbus_interface = "org.gnome.ScreenSaver", signal_name="ActiveChanged")

gobject.MainLoop().run()


Just install the Perl script into irssi, and then run this python service somewhere in your desktop session. Any time your screensaver turns on, you'll go away.

1 comments:

Eric said...

Very cool. I wonder if it works when you are using irssi across ssh which is how I always use it. Will have to experiment with it tonight.