Easy desktop notification system
Tired of having to get clever with your bash scripts so that you can be notified when something happens? What if you want instant notification on an event? Say you run a regular backup sync every, oh, 30 minutes and you want to be notified while you're sitting at you computer the minute it happens. Oh sure you can be emailed on an event, but this requires an email server setup and you have to check your email. What if you just want a simple message to pop up on your desktop informing you that your script has succeeded? Well you can have that with the notify-send command.
The notify-send command allows you to display messages right on the desktop via the notification daemon. These messages are fairly unobtrusive, fit it with your desktop scheme, and are really easy to set up in your scripts. And in this article I am going to show you how you can add this little system for easy message pop ups.
The notify-send tool Â is a part of the libnotify package. So to install this do the following:
- Open up a terminal window.
- Issue the command sudo apt-get install libnotify-bin.
- Enter your sudo password.
- Accept any necessary dependencies.
That's it. You are ready to start using this handy command.
The basic usage for the command is:
notify-send OPTIONS MESSAGE
Let's take a very simple example of popping up the message "Hello Ghacks" on the desktop. To do this you would issue the command notify-send "Hello Ghacks" and hit enter. When you do you will see a small message pop up at the bottom of your desktop as you see in Figure 1. Of course the appearance of this message will depend upon which desktop you are using. I am using GNOME Shell so mine will be a variation on those of you using standard GNOME.
Let's add an image to the message (the image you see in Figure 1 is the default). To add an image you use the -i option. The image used must be a .png file. You can find plenty of these in the /usr/share/pixmaps directory. So I am going to use the GNOME logo to remind me to take a walk. The command would look like:
notify-send -i /usr/share/pixmaps/gnome-about-logo.png "Take a walk!"
And the message would look like the one you see in Figure 2.
When you use this command you will notice the messages don't last very long. You can change that with the -t option. You can set this so the message stays up until the user tell it to go away (by clicking on it) or you can set it to remain in milliseconds. So let's say you want to give yourself a message to take a walk and you want it to remain open for ten seconds. To do this the command would look like:
notify-send -t 10000 -i /usr/share/pixmaps/gnome-about-logo.png "Take a walk!"
Or, if you want that message to remain until you click it away, the command would look like:
notify-send -t 0 -i /usr/share/pixmaps/gnome-about-logo.png "Take a walk!"
You can imagine how much easier it has now become to notify yourself when a script has finished. You no longer have to rely on email messages or hacked-up notifications. Linux has a nice, built-in notification system you can use in your scripting or your cron jobs to let you know the things you need to know.Advertisement