homing pidgin

Just another bit of shell glue which took about twenty minutes but yielded lovely results as it occurred to me that the DICE-wide inventory tools can now locate (at least in theory) any machine.

Being able to find out what office I’m in is more useful a feature than you might think.  Primary of those is the ability to advertise my whereabouts to colleagues, for example on entering a server room, in case I can be of button-pushing assistance to others.  Whenever I move around, I make an effort to update my Jabber status to point this out.

In fact, the glue was very straightforward and I learned about a particularly useful new tool: the Python DBUS libraries.  DBUS is the message bus adopted by most modern “freedesktop”-compatible environments, and the Python library provides a quick and easy way onto the bus.

First, I hacked together a tiny script to establish where I am.  This should really be done more programmatically. But it worked.

/usr/bin/minv `hostname -s` | awk '/located in/ {print $(NF);}'

Then some Python DBUS wrangling:

#!/usr/bin/env python
import dbus
bus = dbus.SessionBus()
obj = bus.get_object("im.pidgin.purple.PurpleService", "/im/pidgin/purple/PurpleObject")
purple = dbus.Interface(obj, "im.pidgin.purple.PurpleInterface")

def set_message(s, message):
  # Get current status type (Available/Away/etc.)
  current = purple.PurpleSavedstatusGetType(purple.PurpleSavedstatusGetCurrent())
  # Create new transient status and activate it
  status = purple.PurpleSavedstatusNew("", current)
  purple.PurpleSavedstatusSetMessage(status, message)

if __name__ == "__main__":

So, gluing it all together:

(sleep 10; pidgin_status.py `whereami`)&

[source: developer.pidgin.im]

Leave a Reply

Your email address will not be published. Required fields are marked *