I don't really blog anymore. Click here to go to my main website.

muhuk's blog

Nature, to Be Commanded, Must Be Obeyed

September 09, 2015

Displaying Clojure Test Results in Taskbar

This is a quick tip if you are using lein-test-refresh on KDE; each time tests are run you can generate a desktop notification with the test results.

To enable this, first we need to add :notify-command to our project.clj:

  ;; ...
  :test-refresh {:notify-command ["/path/to/notify.py" "Tests are run."]})

Then we need to create notify.py script:

#!/usr/bin/env python

import dbus
import sys

def notify(summary, body='', app_name='', app_icon='',
        timeout=5000, actions=[], hints=[], replaces_id=0):
    _bus_name = 'org.freedesktop.Notifications'
    _object_path = '/org/freedesktop/Notifications'
    _interface_name = _bus_name

    session_bus = dbus.SessionBus()
    obj = session_bus.get_object(_bus_name, _object_path)
    interface = dbus.Interface(obj, _interface_name)
    interface.Notify(app_name, replaces_id, app_icon,
            summary, body, actions, hints, timeout)

if __name__ == '__main__':

I have made a small change in the last line of the original script.

Don’t forget to make it executable:

$ chmod +x /path/to/notify.py

If you have any questions, suggestions or corrections feel free to drop me a line.