Home > Scripts > Pop-up notification from the command line

Pop-up notification from the command line

pop-up notifitacionI was looking for a way to tap into the pop-up bubbles that Ubuntu displays notifications in. I wanted to be able to have some scripts run and notify me when they were done. After searching for a little while I finally ran across a post on www.barregren.se.  He goes into pretty good detail about the things that you can do with the notify program.  The first step to getting access to the pop-ups (aka Notify OSD) is to install the program notify-send.  So from the command line enter the following.

sudo apt-get install libnotify-bin

Now from the command line let’s try a couple of quick things.

notify-send 'Hello World!'

For some reason that doesn’t work when I try to use the double quotes (“) instead of the single quotes (‘). It appears to be something with the (!) character. If someone knows why please share.

The next thing I wanted to do was to have some kind of a title for the pop-up. Here is how that works

notify-send 'Title Goes Here' 'The message goes here. If it is a very long message then the message should wrap onto the next line(s).'

The next thing that you may want to do is to put things on multiple lines. The easiest way that I saw on barregren.se was to use the echo command.

notify-send "Title" "$(echo -e "This is the first line.\nAnd this is the second.")"

The following doesn’t work. It all stays on one line.

notify-send "\n doesn't work" "This is the first line.\nAnd this is the second."

Finally you may want to add icons to your messages.

notify-send -i /usr/share/pixmaps/gnome-irc.png "Demonstration" "This is a desktop notification from the command line."

Well there you have it. Now you can add pop-up notifications to your scripts.

Categories: Scripts Tags: , , ,
  1. No comments yet.
  1. No trackbacks yet.