Ubuntu – How to send text messages to the notification bubbles

notify-osdpython

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?

Best Answer

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-notify2 or python3-notify2 and call the notification through that:

import notify2

def sendmessage(title, message):
    notify2.init("Test")
    notice = notify2.Notification(title, message)
    notice.show()
    return