Every desktop environment on Linux has its own notification system which implements the Freedesktop notifications specifications. Some of them, like GNOME or KDE, use their own built-in notification systems which cannot be replaced; others like Xfce or Mate, use more modular components (Xfce notification daemon and Mate notification daemon, respectively). Desktop-independent notification systems also exist (dunst, for example): most of the time they are used on minimal setups (e.g. when using a plain window manager instead of full blown Desktop environments).
In this tutorial we learn how to send desktop notifications from the command line using the notify-send utility.
In this tutorial you will learn:
- How to install notify-send on some of the most used Linux distributions
- How to use the notify-send utility to send desktop notifications
- How to specify a notification urgency and expiration time
- How to use a custom notification icon
|Category||Requirements, Conventions or Software Version Used|
|Other||Administrative privileges to install software|
|Conventions||# – requires given linux-commands to be executed with root privileges either directly as a root user or by use of
The notify-send utility is available on all the major Linux distributions as part of the libnotify library. Most of the times, it is installed by default, however, if for a reason or another it is not, here is how to install it explicitly. On Fedora, and other distributions of the Red Hat family, we can install the library by running the following command:
$ sudo dnf install libnotify
On Debian and Ubuntu, the utilities associated with the libnotify library are distributed in a dedicated package, separated from the library itself. The package is called
libnotify-bin, and can be installed by running:
$ sudo apt install libnotify-bin
On Archlinux, the package we need to install is simply called
libnotify. It is contained in the “Extra” repository and we can install it by using the
pacman package manager:
$ sudo pacman -Sy libnotify
Let’s see how we can use notify-send to send desktop notifications.
How to use notify-send
The notify-send utility takes only one mandatory argument which is the notification summary. In the following example we invoke the utility in this basic way:
$ notify-send "this is the summary"
Here is the result of the command, invoked in the context of the GNOME desktop environment:
When we want to include more information in a notification, we can include a body as the second argument accepted by the utility; it is displayed after the summary. Here is an example of a notification which includes a body and the output it produces:
$ notify-send "this is the summary" "this is the body of the notification"
A limited set of HTML tags can be used inside the notification body:
Consequently we can make so that the text is visualized as bold or italic, use hyperlinks and images.
Specifying the urgency of a notification
There are three urgency levels which can be associated with a notification. They are, in order:
To specify the urgency of a notification when using the notify-send utility, all we have to do is to use the
-u option (short for
--urgency) and pass the urgency level as argument. To send a critical notification, for example, we would run the following command:
$ notify-send -u critical "Critical notification!" "this is the body of the notification"
As you can see from the screenshot below, the icon associated with a critical notification is different from the default one. Critical notifications must be manually dismissed:
Speaking of the expiration time of a notification, it can be easily specified by using the
--expire-time) , which takes the duration time in milliseconds as argument. Just as an example, to send a notification which should expire after 3 seconds, we would run:
$ notify-send -t 3000 "this is the summary" "this is the body of the notification"
As specified in the notify-send manual, however, not all notification system implementations respect this parameters: GNOME always ignores it, while KDE Plasma ignores it for notifications with the “critical” urgency level.
Using a custom notification icon
The notify-send utility provides an option we can use to specify the notification icon. The option is
--icon; it takes the path of the icon we want to use as argument. Imagine we want to send a critical notification about the machine battery level, and use the “critical battery” Adwaita icon, which usually can be found as
/usr/share/icons/Adwaita/scalable/status/battery-level-0-symbolic.svg. Here is the command we would run:
$ notify-send -u critical -i /usr/share/icons/Adwaita/scalable/status/battery-level-0-symbolic.svg "Connect charger!" "critical battery level, please connect charger"
Here is the notification produced by the command above:
In this article we learned how to use the notify-send utility to send desktop notifications from the command line; an ability which can be especially useful in shell scripts. We learned how to install the utility on some of the most used Linux distributions, how to specify a notification body and summary, how to specify the urgency of a notification and its expiration time, and how to use a custom icon for a notification. To know more about the Freedesktop notifications specifications you can consult the online documentation.