notification-daemon

I was wrong.

After looking around some more, I found that there is a notification-daemon package that uses D-BUS.

"D-Bus is a message bus system, a simple way for applications to talk to one another."

There is libnotify, which is a library to send notifications through D-BUS, and there is libnotify-bin, which contains a tool "notify-send" to send single notifications.

There are also Python bindings in python-notify, which can be used to post notifications to D-BUS, through libnotify. Too complicated ? Not really.

I was so fixed on creating a "file watching daemon" that would constantly query a file, read new lines and post those as notifications.
I decided to create such a daemon using the python bindings, and it actually works nicely.


#!/usr/bin/python
import time
import string
import gtk, pynotify

pynotify.init("test")

TypeImages = {
'info': "icon.png",
'alert': "/usr/share/app-install/icons/blam.png"
}
TypeTitles = {
'info': "Informational",
'alert': "Alert"
}


fp=open('/tmp/workfile', 'r')

lastdate = int(time.time())
while 1:
line = fp.readline()
while line:
line = line.rstrip()
parts = line.split(" ", 2)
i = line.find(" ") # let's assume this is not -1
ts = line[0:i]
line = line[i+1:]

i = line.find(" ") # let's assume this is not -1
tag = line[0:i]
rest = line[i+1:]

if lastdate <= int(ts):
#print "[" + ts + "][" + rest + "]"
if TypeTitles.has_key(tag):
n = pynotify.Notification(TypeTitles[tag], rest)
p = gtk.gdk.pixbuf_new_from_file(TypeImages[tag])
n.set_icon_from_pixbuf(p)
else:
n = pynotify.Notification("Unknown", rest)

n.show()

line = fp.readline()

lastdate = int(time.time())
time.sleep(1)

fp.close()


This program works nicely, but there is no advantage over calling notify-send manually. Well, not a lot anyway.

So instead of creating a new package with this daemon in it, I'll just use notify-send everywhere (or maybe write a wrapper around it)

For example:

notify-send -i /usr/share/app-install/icons/kalarm.png "Test"