notify-send - Linux
Overview
The notify-send
command is a utility in Linux that triggers a desktop notification to appear on the user’s screen. Notifications created by notify-send
are useful for alerting the user after a long-running process has completed or for displaying system information in a non-intrusive way. The command interfaces with the desktop’s native notification system, making it widely applicable in desktop scripting and automation.
Syntax
The basic syntax of the notify-send
command is:
notify-send [OPTIONS] <SUMMARY> [BODY]
<SUMMARY>
: The title or main text of the notification.[BODY]
: The optional secondary text which provides more detail.
Options/Flags
The notify-send
command offers several options:
-u, --urgency=LEVEL
: Sets the urgency level (low, normal, critical).-t, --expire-time=TIME
: Time in milliseconds for the notification to expire. The default is to follow system settings or remain until dismissed.-i, --icon=ICON[,ICON...]
: Specifies an icon filename or stock icon to display alongside the notification.-c, --category=TYPE[,TYPE...]
: Specifies the notification category.-h, --hint=TYPE:NAME:VALUE
: Supplies extra data in the form of key-value pairs.
Typical use cases involve specifying urgency, an icon, and expiration time to tailor the notification depending on the context it’s used.
Examples
-
Basic Notification:
notify-send "Hello, World!"
Displays a basic notification with the text “Hello, World!”.
-
Notification with Title and Body:
notify-send "Reminder" "Meeting at 3 PM"
Shows a notification titled “Reminder” with more details in the body.
-
Notification with Urgency and Icon:
notify-send -u critical -i error "Alert" "Temperature too high!"
Displays a critical urgency notification with an error icon.
-
Notification with Expiration Time:
notify-send -t 10000 "Break" "Time to relax!"
This notification will expire after 10 seconds.
Common Issues
- Urgency Levels Not Respected: Some desktop environments may not support different urgency levels or may treat them the same.
- Persistent Notifications: If
-t 0
is used, notifications may not expire as intended depending on the desktop settings.
Workaround: Ensure compatibility with your desktop environment, and avoid setting a zero timeout unless desired.
Integration
Script Completion Notification:
Imagine running a backup script and wanting a notification when it finishes:
#!/bin/bash
# Backup script example
tar -czf backup.tar.gz /my/directory
notify-send "Backup Complete" "Your files are now safe."
Combining with Cron Jobs:
Schedule a reminder every Monday morning using cron
:
0 9 * * 1 notify-send "Weekly Meeting" "Don't forget the team meeting at 10 AM."
Related Commands
zenity
: Tool for displaying dialog boxes in the GUI.xmessage
: Older tool for displaying alert text in a window.
For more advanced usage, refer to the freedesktop.org notifications specifications.