Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
up vote 44 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])

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

import pynotify

def sendmessage(title, message):
    notice = pynotify.Notification(title, message)
share|improve this answer
Thank you very much – Anuroop Kuppam Feb 29 '12 at 12:35
+1 Great answer! – César Feb 29 '12 at 14:42
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


Whilst you can call notify-send via os.system or subprocess it is arguably more consistent with GTK3 based programming to use the Notify gobject-introspection class.

A small example will show this in action:

from gi.repository import GObject
from gi.repository import Notify

class MyClass(GObject.Object):
    def __init__(self):

        super(MyClass, self).__init__()
        # lets initialise with the application name

    def send_notification(self, title, text, file_path_to_icon=""):

        n =, text, file_path_to_icon)

my = MyClass()
my.send_notification("this is a title", "this is some text")
share|improve this answer
import os
os.system('notify-send '+mstr)
share|improve this answer
How do I customize this notification? Like heading, image in notification, etc.? – Mehul Mohan Mar 25 '15 at 18:34

To answer Mehul Mohan question as well as propose the shortest way to push a notification with title and message sections:

import os
os.system('notify-send "TITLE" "MESSAGE"')

Putting this in function might be a bit confusing due to quotes in quotes

import os
def message(title, message):
  os.system('notify-send "'+title+'" "'+message+'"')
share|improve this answer
You could suggest an edit to that post. – muru Oct 26 '15 at 10:25

Your Answer


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.