Florijan

Do your deed

HOWTO: Using Python to display notifications with libnotify

May22

You’ve just written you neat python script and you need just a notification system so you know what happenes what your script is finished. For me – best thing for wget downloading and I’m surfing around – little notification pops out when I’m done.
All you need is a libnotify package (Debian users install also the libnotify-bin package).
And.. What to do?

Here is an example:

Let’s say I want to know what is my kernel version and IP address.

[code lang="python"]#!/usr/bin/python
import subprocess
import commands

#KERNEL VERSION
uname = commands.getoutput('uname -r')
#Your IP Adress
ip = commands.getoutput('curl -s http://checkip.dyndns.org/ | grep -o "[[:digit:].]\+"')
#
#COMBO
#
head = "All the info about your system:"
msg = "Your kernel version: "+ uname +"\n"
msg += "Your IP address: "+ ip +""

subprocess.call(['notify-send', head, msg])[/code]

And there you have it!
Just run the

[code]notify-send “Headmsg” “This is a test”[/code]

And your notification will be displayed to your attention.

(This script requires the curl package – so check if it is installed :) )

posted under linux, python
3 Comments to

“HOWTO: Using Python to display notifications with libnotify”

  1. On May 30th, 2009 at 15:46 Pedro Says:

    Wow, a great feature! I love it!

  2. On July 21st, 2009 at 10:40 twister Says:

    nice & useful

  3. On November 16th, 2009 at 14:30 Hermano Arco Says:

    A bit more pythonic way would be with pynotify as seen here: http://roscidus.com/desktop/node/336

Email will not be published

Website example

Your Comment: