In this article, we will explore how to send custom desktop notifications in Ubuntu using the
notify-send command. This command-line utility is part of the
libnotify-bin package and allows you to send custom notifications to the desktop user.
To send custom desktop notifications in Ubuntu, you can use the
notify-send command-line utility. This tool allows you to display notifications with custom titles and messages, as well as options for displaying command output, using icons, controlling duration, setting urgency level, and sending notifications from cron.
Before we get started, let’s ensure that
notify-send is installed on your system. If not, you can install it using the following command:
sudo apt-get install libnotify-bin
Basic Usage of notify-send
The basic syntax of the
notify-send command is as follows:
notify-send "<title>" "<message>"
<title> is the title of your notification and
<message> is the content of your notification. For example:
notify-send "Hello" "This is a custom notification."
This command will display a notification with the title “Hello” and the message “This is a custom notification.”
Advanced Usage of notify-send
Displaying Command Output
If you want to display the output of a command in the notification, you can use command substitution. Here’s an example:
notify-send "Date" "$(date)"
This command will display a notification with the title “Date” and the message as the current date and time.
You can also use icons with your notifications. To do this, use the
-i option followed by the name or path of the icon. For example:
notify-send -i info "Information" "This is an informational message."
This command will display a notification with an information icon, the title “Information”, and the message “This is an informational message.”
To control the duration of the notification, use the
-t option followed by the duration in milliseconds. For example:
notify-send -t 5000 "Hello" "This message will disappear after 5 seconds."
This command will display a notification that disappears after 5 seconds.
Setting Urgency Level
You can set the urgency level of the notification to low, normal, or critical using the
--urgency option. For example:
notify-send --urgency=critical "Warning" "This is a critical message."
This command will display a critical notification with the title “Warning” and the message “This is a critical message.”
Sending Notifications from Cron
If you want to send a notification from a script running in cron, you may need to specify the display using the
DISPLAY environment variable. For example:
DISPLAY=:0.0 notify-send "Hello" "This is a custom notification."
notify-send command is a powerful tool for sending custom desktop notifications in Ubuntu. By understanding its various options and how to use them, you can create notifications that are tailored to your specific needs. Whether you’re displaying the output of a command, using icons, controlling the duration, setting the urgency level, or sending notifications from cron,
notify-send has got you covered.
To change the appearance of the desktop notifications, you can modify the theme settings in your Ubuntu system. Open the "Settings" app, go to "Appearance", and select the desired theme. This will affect the appearance of the notifications as well.
By default, the desktop notifications appear at the top right corner of the screen. Unfortunately, there is no built-in option to change the position of the notifications using the
notify-send command. However, you can use third-party tools or extensions to customize the position of the notifications on your Ubuntu desktop.
notify-send command does not support adding buttons or actions to the desktop notifications. It is a simple utility for displaying basic notifications. If you need more advanced functionality, you may need to explore other notification systems or libraries available for Ubuntu.
If you want to disable desktop notifications temporarily, you can use the command
killall notify-osd to stop the notification service. To disable notifications permanently, you can go to the "Settings" app, select "Notifications", and disable the notifications for the specific applications or globally.
notify-send command itself does not have built-in scheduling capabilities. However, you can use other tools like cron or systemd timers to schedule the execution of the
notify-send command at a specific time or interval.
To change the sound played for desktop notifications, you can go to the "Settings" app, select "Sound", and modify the notification sound settings. You can choose from the available sound options or add custom sound files to be used for notifications.