
To do this, all we need to do is use the notify-send terminal command.
notify-send "Summary" "Body"
As usual, we can also pass the output of other commands. For example, of the command date.
notify-send "Now is..." "$(date)"
Displaying a Custom Icon
To display a custom icon we can use the --icon argument with a filepath to the icon.
notify-send "Error!" "--icon=/usr/share/icons/Mint-X/status/32/dialog-error.png"
This works, so long as you have Mint-X installed.
Displaying a Button
We can add a button to the notification with the --action argument. Normally, notify-send returns immediately even while the notification stays on screen, but if you use --action, then notify-send will block until a button is pressed.
notify-send "--action=details=Tell me more" "--action=silence=Silence!" "You won't be believe!" "Something amazing has happened!"
Above, we defined two actions, the first reads "Tell me more" and the second reads "Silence!". If we click on the first one, notify-send will print "details" to STDOUT as we specified. If we click on the second one, it prints "silence".
Tip: observe that we must wrap the --action argument in double quotes in order to have spaces in the label for the button.
If the user clicks on the X button to close the notification, notify-send returns but nothing is printed.
Warning: if the user ignores the notification, then notify-send won't return. More specifically, the notification will disappear and stays in the notification area in the system tray. notify-send only returns if the user opens the notification area and clicks on a button to dismiss the notification.
If you terminate notify-send (e.g. by pressing Ctrl+C on the terminal), the notification will be removed automatically.
It's possible to make use of the return value like this for example:
ANSWER=$(notify-send "--action=ok=Open Youtube" "New Video Warning" "Your favorite Youtuber posted a new video.")
if [ "$ANSWER" = "ok" ]; then
# code to open Youtube goes here
fi
Above, we store the return value of notify-send in a variable, and if it's ok, in other words, if the user did click the button, then we perform a specific task, e.g. opening Youtube.