Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I wrote a python code for getting random text into a .txt file. Now I want to send this random text into notification area via 'notify-send' command. How do we do that?

share|improve this question
add comment

1 Answer

up vote 22 down vote accepted

We can always call notify-send as a subprocess, e.g like that:

#!/usr/bin/env python
#-*- coding: utf-8 -*-

import subprocess

def sendmessage(message):
    subprocess.Popen(['notify-send', message])
    return

Alternatively we could also install python-notify Install python-notify and call the notification through that:

import pynotify

def sendmessage(title, message):
    pynotify.init("Test")
    notice = pynotify.Notification(title, message)
    notice.show()
    return
share|improve this answer
    
Thank you very much –  bobbyaldol Feb 29 '12 at 12:35
    
+1 Great answer! –  César Feb 29 '12 at 14:42
1  
I had to use subprocess.Popen(['notify-send', message]) to make the first example work. –  lgarzo Feb 29 '12 at 16:52
    
The second one a pynotify.init("Test") and pynotify.Notification(title, message).show(). By the way I'm „Learning Python The Hard Way”, so I might just overlook something... –  lgarzo Feb 29 '12 at 17:07
    
So sorry for that. I was unable to test this earlier on my box at work - my bad. Edited the missing bits in. –  Takkat Feb 29 '12 at 17:21
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.