Ubuntu features a notification system, where you can see a message notifying you about some particular event. Rhythmbox uses it to show the next track when a track ends, Filezilla shows a notification that file transfers are completed when its window is not in focus (Very handy!) and so on several applications can use it to notify users in the same way (keeping the UI consistent, which is a good design principle).
Rhythmbox Song Notification
Filezilla Transfer Complete Notification
We too can use this easily in our shell scripts. It supports more functionality if you are working in Python or C (Read Ubuntu NotifyOSD) but for shell scripts it does the pretty fine job too, if you just want to make Ubuntu work for you.
Using NotifyOSD in shell scripts
Make sure you have libnotify-bin installed, if not, just install it by typing the following command in a terminal:
sudo apt-get install libnotify-bin
notify-send - Program to send desktop notifications
With notify-send you can sends desktop notifications to the user via a notification daemon from the command line. These notifications can be used to inform the user about an event or display some form of information without getting in the user’s way.
Check out the man page for it, to see the options it has to offer - man notify-send
Enter this in a terminal, notify-send "Hello" "this is just a test" and you will see the notification appearing up on your desktop.I usually collect icons that I would like to use and then use them in notification bubbles in the following manner:
In terminal, you can use it like
notify-send -t 2000 -i /home/ashfame/Dropbox/Ubuntu/icons/console.png "Hello Ashfame" "This is your computer, lets start with work"
In a shell script, use it like (take care of the screen where you want to display the message - I am on a dual screen setup)
DISPLAY=:0 notify-send -t 2000 -i /home/ashfame/Dropbox/Ubuntu/icons/console.png "Hello Ashfame" "This is your computer, lets start with work"
Time parameter (-t) lets you specify the time in miliseconds after which the notification will fade away. Its affected with a bug right now (will work on the default timeout even if you set it, but will be fixed in upcoming releases anyway, so better use it).
Icon parameter (-i) is used to specify the icon which is to be used in the notification.
You can also use it to notify you when a certain command has completed in the terminal, like when you were compiling some code or anything which takes a good amount of time so that you can get to know the moment it is ready. As an example, you can use it like
make && notify-send "DONE"
Making practical use of NotifyOSD using notify-send
You can create shell scripts for additional functionality you want, right? Just use notify-send where you want you to be informed or alerted.
Here are the examples, where I use them:
- WordPress new version alert
- Alert if my site is down
- Health check - Tells me to take breaks, sleep at night and if I resist, lock the screen
- Pomodoro technique for quantizing time for increasing productivity
- Random fun facts from randomfunfacts.com
You can build a lot more useful stuff as per your needs. Share your ideas in the comments and we can discuss 🙂