Skip to content

Using libnotify and Python

August 14, 2010

Ubuntu 9.04+ has a pretty nice looking notification system. Unfortunately I couldn’t find much online on how to use this, but after some digging on my own system, I found some examples and documentation. The package’s name is libnotify1, and there is a python wrapper library for it called python-notify.

To install it python-notify you can simply run

shreyas@box:~$ sudo apt-get install python-notify

Of course, I will show you some code on how to use it, although you can always look at the examples located in /usr/share/doc/python-notify/examples .


#!/usr/bin/python

import pygtk
pygtk.require('2.0')
import pynotify
import sys

if __name__ == '__main__':
    if not pynotify.init("Basics"):
        sys.exit(1)

    n = pynotify.Notification("Summary", "This is some sample content")

    if not n.show():
        print "Failed to send notification"
        sys.exit(1)

This is straight from an example I found in /usr/share/doc/python-notify/examples.

About these ads

From → Linux Tutorials

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: