HOWTO: Using Python to display notifications with libnotify
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
)
Wow, a great feature! I love it!
nice & useful
A bit more pythonic way would be with pynotify as seen here: http://roscidus.com/desktop/node/336