Most of the application can show nicely formatted notification on events that appear on top right corner of the screen. I'm about to write a bash script that will do fairy long processing in the background and I really want to know when it is finished. How can I show that nice notification from a bash script?
-
1How can I trigger a notification when a job/process ends? – phuclv Jul 27 '15 at 11:59
-
Bonus question: Can you put the notification on certain output only? What if you use screen mirroring? – jarno Feb 3 '20 at 13:36
If you're using the new notification system in Jaunty, you want the notify-send command
notify-send - a program to send desktop notifications
SYNOPSIS
With notify-send you can sends desktop notifications to the user via
a notification daemon from the command line. These notifications can be
used to inform the user about an event or display some form of information
without getting in the user's way.
OPTIONS
-u, --urgency=LEVEL
Specifies the urgency level (low, normal, critical).
-t, --expire-time=TIME
Specifies the timeout in milliseconds at which to expire the notification.
-i, --icon=ICON[,ICON...]
Specifies an icon filename or stock icon to display.
-c, --category=TYPE[,TYPE...]
Specifies the notification category.
-
4Thanks, just found it myself :) apt-get install libnotify-bin have to be run before to get it. – vava Aug 29 '09 at 10:39
-
How does the root user send a message from crons, init.d, etc? – Lance Caraccioli Nov 22 '13 at 4:38
-
6
-
3The --expire-time parameter does not work on Ubuntu thanks to this "feature" (bug). bugs.launchpad.net/ubuntu/+source/notify-osd/+bug/390508 – axiopisty Apr 18 '16 at 15:43
-
1I couldn't take it; I had to write my own answer :) superuser.com/a/1310142/425838 – Gabriel Staples Apr 2 '18 at 18:15
Found another way, through Zenity
echo 'message:hi' | zenity --notification --listen
or like this:
zenity --notification --text "System update necessary!"
(This also has the benefit of already being installed on Ubuntu.)
-
I like Zenity in that it supports user interactions for dialogs (unlike notify-send) – Waffle's Crazy Peanut Jan 21 '18 at 13:32
Tested on Ubuntu 14.04, 16.04, 18.04, 20.04. Screenshots from Ubuntu 20.04.
[WORKS WELL] Popup notification that auto-closes after 4~10 seconds (somehow tied to your OS settings?):
notify-send "Hello world"
Popup window with buttons to click:
Window does NOT get auto-focus: Source: myself; note: for older Unity-based versions of Ubuntu, such as 16.04,
-t
is ignored for all values except 0--how stupid. :(. For newer Gnome-based versions of Ubuntu, such as 18.04 or 20.04,-t
is ignored entirely. Therefore, on older Unity-based versions of Ubuntu, such as 16.04, using-t 0
causes buttons to show up, but on newer Gnome-based versions, it does NOT. That means that for the Ubuntu 20.04 screenshot shown below, the behavior and look ofnotify-send -t 0 "Hello world"
is exactly identical tonotify-send "Hello world"
above.notify-send -t 0 "Hello world"
On Ubuntu 18.04 or 20.04 or later, just add
-u critical
to the command instead to get it to stay open indefinitely until you click anywhere on it!:notify-send -u critical "Hello world"
Source: @lucidbrot's comment below this answer, plus my own testing.OR Window DOES get auto-focus:
zenity --info --title "Hello" --text "World"
Note: the window will NOT close until you click the OK button.
Source: https://askubuntu.com/a/804475/327339
[MY FAVORITE] The window auto-closes after the specified
--timeout
in seconds, OR after you click the "OK" button!zenity --info --title "Hello" --text "World" --timeout=2
Note: the window WILL automatically close after the specified timeout above, in seconds!
Source: myself reading the man pages:man zenity
[super ugly-looking]
xmessage 'hello world'
Note: the window will NOT close until you click the okay button.
Source: http://www.linux-commands-examples.com/xmessage
-
1My notification with
-t 0
disappears by itself unless the level iscritical
just like the others. I'm on Ubuntu 18.04. But the other options work great, and the[super ugly-looking]
made me laugh – lucidbrot Jul 30 '20 at 10:13
For KDE users:
$ kdialog --title "Long process completed!" --passivepopup "This popup will disappear in 5 seconds" 5 &
There's also xmessage that will pop-up a window, so it should work on any X11 system.
Pro: It also allows interactively prompting the user with buttons.
Con: Like any pop-up alert, it typically receives focus, so if you're in the middle of typing it can disappear before you read the message.
-
4Con: It looks ugly as hell, and also is a super tiny window which is not always obvious to the user. Anyways, it is universal though. :) – Nik Reiman May 6 '13 at 11:37
-
xmessage doesn't work in Fedora though. Its not installed by default. – Abhay Mittal Jun 3 '14 at 16:47
-
It's not available in the default Xorg installation of Arch Linux either. – friederbluemle Jan 22 '18 at 8:06
-
You can also get a popup window with an "OK" and "Cancel" button via
notify-send --expire-time=0 "Hello World"
ornotify-send -t 0 "Hello world"
. Otherwise, however, the-t
option is ignored due to some stupid "design decisions": askubuntu.com/questions/110969/notify-send-ignores-timeout – Gabriel Staples Apr 2 '18 at 18:04 -
I couldn't take it; I had to write my own answer :) superuser.com/a/1310142/425838 – Gabriel Staples Apr 2 '18 at 18:15
There exists a cross-platform solution called Yfiton:
$ yfiton -n desktop -Pmessage="Lunch time!" -Pposition=TOP_RIGHT
In a shell script, you can also call the osd_cat utility from libxosd.