Archive for the 'Python' Category

How to set the urgency hint for new mail in Thunderbird

Some window managers, including i3wm, the one I use at the moment, highlight windows and desktop tabs when the window or one of it’s children sets the X urgency hint. irssi, for example, supports that, allowing for nice and silent notifications when somebody querys or mentions you. However, even after hours of googeling, I couldn’t find any way to make Thunderbird set this flag when new mail arrives. This is why I came up with my own solution. I wrote a python script that finds the Thunderbird window and set’s the urgency hint using the python-xlib (which you would have to install yourself!) bindings. I then installed the Thunderbird extension Mailbox Alert, that allows you to specify scripts to be executed when new mail arrives – even on a per-folder basis. (The extension is pretty awesome, you should definitely check it out!) With that, everything works perfectly now.

The script setting the urgency hint is pretty basic. Here it is:

#!/usr/bin/python2

from Xlib import X, display, Xutil

def find_window(name, w):
    for win in w.query_tree().children:
        if win.get_wm_class() and win.get_wm_class()[1] == name:
            return win
       
        if len(win.query_tree().children) > 0:
            a = find_window(name, win)
            if a:
                return a

def main(disp):
    win = find_window("Thunderbird", disp.screen().root)
    hints = win.get_wm_hints() or { 'flags': 0 }
    hints['flags'] |= Xutil.UrgencyHint

    win.set_wm_hints(hints)
    disp.flush()
   
if __name__ == '__main__':
    main(display.Display())

Openbox pipemenu to control virtual machines of VirtualBox

Openbox, Virtualbox… Coincidence? I don’t know. Anyway, I am a huge fan of VirtualBox, for the virtual machines are extremely fast, stable and nice to control. With the command line tool VBoxManage comes a nice tool for all those CLI-lovers out there. You can literally do anything with it, what the GUI can do. (at least it looks like that)

Now, starting the GUI to start a VM is a bit slow, so VBoxManage startvm "vm" is a huge time- and memorysaver.
Since I work with Openbox, the natural thing for me was to google for a suitable pipemenu. Unfortunately, I couldn’t find one. Long story short: Here is my self-written Openbox pipemenu to control VirtualBox’s VMs. (It can start and stop them, at least.)
Continue reading ‘Openbox pipemenu to control virtual machines of VirtualBox’