Need to cause a notification in 12.04 from shell
Solution 1
You can use the default notification daemon to give notifications with an icon.
Just add this line to the shell script where you want to give notification (with appropriate lines and paths).
notify-send -u critical -i <Icon-path> "<Heading>" "<Rest of the message>"
The package providing this is libnotify-bin
.
@ThatJackElliott Did you replace <> with appropriate text? You need to remove "<" ">". Icon path is optional. Try this :
notify-send -u normal "Hello Jack Elliot" "This is a trial notification.\nWelcome to AskUbuntu\!"
-u
can be low, normal & critical.
See man notify-send
for more info.
In case of any problems, these are the packages in my system. They work excellently :
- gir1.2-notify-0.7
- libknotifyconfig4
- libnotify-bin
- libnotify-dev
- libnotify0.4-cil
- libnotify4
- notify-osd
- notify-osd-icons
- python-notify
- python-pyinotify
- xfce4-notifyd
- xfce4-notifyd
Solution 2
yeah you can do that with python. open your terminal and type
sudo apt-get install python-notify
Then write a program like this .
frank@august:~$ cat>not.py
#!/usr/bin/python
import sys
import pynotify
if __name__ == "__main__":
if not pynotify.init("icon-summary-body"):
sys.exit(1)
n = pynotify.Notification(
"Hi Elliott",
"welcome to askUbuntu!",
##dont remove the below line
"notification-message-im")
n.show()
frank@august:~$
save it with any name , for example noti.py for our case .
open your terminal and type python not.py
Then you will see
Hope that helps.
Credit goes here : Create custom notification on your Ubuntu desktop using python
That Jack Elliott
Updated on September 18, 2022Comments
-
That Jack Elliott over 1 year
I'm running Lubuntu 12.04. I have a shell script that tests for a network condition and need some way for it to pop up a notification in the GUI. The network testing part is done, but I need some help with the "pop up a notification in the GUI" part.
-
That Jack Elliott over 11 yearsHi, thanks for the suggestion, but I can't get this to work. When I run the script I get:jack@jack-Aspire-one:~/bin$ sh notify.py notify.py: 2: notify.py: import: not found notify.py: 3: notify.py: import: not found notify.py: 6: notify.py: Syntax error: "(" unexpected (expecting "then") jack@jack-Aspire-one:~/bin$
-
That Jack Elliott over 11 yearsWait, sorry, I didn't run the script correctly. I also can't figure out how to enter line breaks in this comment box, nor put the terminal results in a neat little box, so my responses are a bit of a mess. The python script is still returning an error: jack@jack-Aspire-one:~/bin$ python notify.py Traceback (most recent call last): File "notify.py", line 14, in <module> n.show() glib.GError: GDBus.Error:org.freedesktop.DBus.Error.ServiceUnknown: The name org.freedesktop.Notifications was not provided by any .service files jack@jack-Aspire-one:~/bin$
-
mx7 over 11 yearshave you installed python-notify ?
-
VedVals over 11 yearsRun
dpkg -l | grep notify-send
and see if you get any output. -
That Jack Elliott over 11 yearsNope, no output.
-
VedVals over 11 years@ThatJackElliott Sorry, I gave the wrong name. Try
dpkg-query -l libnotify-bin
ORdpkg -l | grep libnotify-bin
. If no output, install libnotify-bin. Its available in the repos. -
That Jack Elliott over 11 yearsLooks like I have libnotify-1 v 0.7.5-1 installed.
-
VedVals over 11 yearsAnd notify-send isn't working? Its a bug. Report it.
-
VedVals over 11 yearsJust to be sure, recheck the code in answer. I found an unnecessary quote in it. Typo mistake.
-
That Jack Elliott over 11 yearsjack@jack-Aspire-one:~$ notify-send -u normal "Hello Jack Elliot" "This is a trial notification.\nWelcome to AskUbuntu\!" jack@jack-Aspire-one:~$ no response. Dang, how does one enter a line break in this comment box?
-
VedVals over 11 years@ThatJackElliott OK, that command works perfectly on my system. And I have the same version of libnotify-bin. Check for similar bugs on Launchpad. Also try re-installling it.
-
That Jack Elliott over 11 yearsOkay, removed and re-installed libnotify-bin, still no joy. Since that doesn't work, what else can be used from a shell script to pop up a notification in Lubuntu's GUI?
-
VedVals over 11 years@ThatJackElliott Completely out of ideas. Except one crazy idea. I'd suggest installing an additional DE. Look at this question and take your pick. Alternatively, if the other solution works then you can write a custom command and put it in
/bin
so that it behaves like a regular command. Experiment with both suggestions, see what you like. -
That Jack Elliott over 11 years[SOLVED]: notification-daemon was not installed. Now notify-send works. And I figured it out all by myself!! I'm so proud. I wonder if notification-daemon will autostart after a reboot.
-
VedVals over 11 years@ThatJackElliott Did it auto start? Also can you accept an answer? (Preferably mine but no pressure) ;-)
-
That Jack Elliott over 11 yearsVedVals: In Lubuntu's Desktop Session Settings, there is an entry for Notification Daemon under "Automatically Started Applications," which was not ticked, so I ticked the box. I haven't needed to restart the computer so I can't confirm that the daemon starts automatically, but I'll keep an eye on it the next time I need to restart the laptop. Thanks for all your help!