Tuesday 31 May 2011

Query the Gnome screensaver using DBUS and Ruby

At my current work place, I need to send a mail every week with the amount of hours I have clocked in that week. Since I am a fairly lazy person, this can be somewhat problematic to remember (and results in annoying monthly mails from my manager). To help this, I have created a script to monitor my hours.

It is a simple script that works on the assumption that the first and last thing I do at work is something involving moving my mouse at the desk (the assumption is fairly correct). The script is a quick thing done in Ruby, with this essential part:


require 'dbus'

bus = DBus::SessionBus.instance
ss_serv = bus.service("org.gnome.ScreenSaver")
ss_obj = ss_serv.object("/org/gnome/ScreenSaver")
ss_obj.introspect
ss_obj.default_iface = "org.gnome.ScreenSaver"
while true:
  if not ss_obj.GetActive then
    on_work
  end
  sleep 10
end


This code basically polls the screensaver every 10 seconds and calls a function to say that I am currently at work. I have not included the on_work - function. This is also a fairly simple thing that uses a PStore to persistently store the first and last time the screen saver is not in use - code not included because of risk of embarrassment. 

1 less angry manager and learning more Ruby in the progress, that is what I call a win-win situation!

Sunday 15 May 2011

My new dev blog

I know this is somewhat last decade, but I finally decided to start a a small dev blog to get some experience with telling others (even if it might be the wall only for the time being).

So, not much planned yet to talk about, but it will probably be around what I work/have worked with, which is image processing, OpenGL ES, mobile computing, Ruby and search engines. So basically a nice potpourri of anything I am interested in :-)