command line - Showing notification in Ubuntu based installs - Ask Ubuntu


i (trying) write simple python script ubuntu based os. part of script, notification shown. now, have gone through number of posts on here each 1 have accompanying question (and problem). following different ways, have tried (and associated issue),

using notify2

this has largely worked well. however, following issue,

a. reason, icon isn't being shown in notification bubble , there no error. simple print statement,print(os.path.abspath('icon.svg'), returning path, yields correct path still no image.

here's exact code using,

def show_notification(title, content):     notify2.init(title)     n = notify2.notification(title, content, os.path.abspath('icon.svg'))     n.show() 

using gi.repository import notify

following hello-unity file here. tried use notify. have not been able running @ all! last time tried, got error importerror: cannot import name notify running script python test.py.

running same using python3 in python3 test.py results in different error importerror: cannot import name notify, introspection typelib not found.

to overcome this, did try install python-gobject , libnotify-bin these installed on system (elementary os loki). errors still persists.

using subprocess

this has worked without problem not sure if best way show notification since intend show regular notifications. code used,

import subprocess s s.call(['notify-send','foo','bar']) 

core question

since first time trying develop linux community (or rather ubuntu), new linux development. trying search simple (and correct) implementation such of notification has been rather time consuming , confusing. apart suggesting right way of implementing notifications, appreciate if point me in right direction, android developer guide shows or has api references.

and before asks development preferences, more comfortable python. regarding gui, again not sure path take although gtk seems more popular.

calling notifications applications on ubuntu

definitely third one, using either subprocess.call() or subprocess.popen(). noting import subprocess. nothing new install. simple , easy, works perfectly.

a few examples:

  1. simply text notification:

    subprocess.popen(["notify-send", "some text"]) 

    enter image description here

  2. a title , text:

    subprocess.popen(["notify-send", "title", "some text"]) 

    enter image description here

  3. an icon, title , text:

    img = "/path/to/icon.png" subprocess.popen(["notify-send", "-i", img, "title", "some text"]) 

    enter image description here


Comments

Popular posts from this blog

download - Firefox cannot save files (most of the time), how to solve? - Super User

windows - "-2146893807 NTE_NOT_FOUND" when repair certificate store - Super User