Easy desktop notification system - gHacks Tech News

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.

Installation

The notify-send tool  is a part of the libnotify package. So to install this do the following:

  1. Open up a terminal window.
  2. Issue the command sudo apt-get install libnotify-bin.
  3. Enter your sudo password.
  4. Accept any necessary dependencies.

That's it. You are ready to start using this handy command.

Usage

The basic usage for the command is:

notify-send OPTIONS MESSAGE

Figure 1

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!"

Figure 2

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!"

Final thoughts

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.





  • We need your help

    Advertising revenue is falling fast across the Internet, and independently-run sites like Ghacks are hit hardest by it. The advertising model in its current form is coming to an end, and we have to find other ways to continue operating this site.

    We are committed to keeping our content free and independent, which means no paywalls, no sponsored posts, no annoying ad formats (video ads) or subscription fees.

    If you like our content, and would like to help, please consider making a contribution:

    Comments

    1. jake said on June 8, 2010 at 2:11 pm
      Reply

      aw, very nice. thanks!

    2. szekelya said on June 8, 2010 at 3:07 pm
      Reply

      Is there anything like this for windows?

    3. Dotan Cohen said on June 8, 2010 at 10:21 pm
      Reply

      Have you switched from Fedora to Ubuntu? You might want to call these Ubuntu tricks, not Linux tricks.

    Leave a Reply