Add Desktop Notifications to Shell Scripts with notify-send

Dmitri Popov

Productivity Sauce

Jan 13, 2015 GMT
Dmitri Popov

Monitoring a running shell script usually means keeping an eye on the terminal window. Obviously, that's not the most productive way to spend your time, so instead of staring at the terminal, you can equip shell scripts with desktop notifications that give you visual feedback when specific events occur. One possible solution is to use the notify-send command which is part of the libnotify package. To install it on Debian or Ubuntu, run the apt-get install libnotify-bin command as root. Using notify-send couldn't be easier. Simply add the command followed by the message text in the desired place in the script as follows:

notify-send "Hello world!"

The command supports a few parameters that can be used to specify the urgency level, expiration time, category, and icon. To view all the supported options along with their descriptions and usage, run the notify-send -? command.

comments powered by Disqus
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters

Support Our Work

Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.

Learn More