Tech Tip: Get Notifications from Your Scripts with notify-send

September 2nd, 2009 by Kristofer Occhipinti in

Your rating: None Average: 4.7 (26 votes)

Notify-send is a great application for notifying you when an event has occurred. An event such as a script running to completion.

If notify-send is not installed on your machine already, install the package "libnotify1" (or possibly just "libnotify") from your repositories.

Once installed you can simply type the following, at the command line, to display a pop-up message near your system tray:

notify-send "hello"

By default the message will be displayed for 5 seconds. To change how long a message stays displayed use the "-t" switch. This will change, in milliseconds, how long the message is displayed. Enter "-t 0" to leave the message up until the user closes it.

notify-send "This message will be displayed for 3 seconds" -t 3000
notify-send "Click me to close me." -t 0

You can even add a title and an icon to the notification.

notify-send "This is the Title" \
            "Check out the cool icon" \
            -i /usr/share/pixmaps/gnome-terminal.png

When used in a script you could set it to notify you periodically by placing the command in a loop:

#!/bin/bash

while [ 1 ]; do
     notify-send "Up Time" "`uptime`"
     sleep 5m
done
__________________________


Special Magazine Offer -- Free Gift with Subscription
Receive a free digital copy of Linux Journal's System Administration Special Edition as well as instant online access to current and past issues. CLICK HERE for offer

Linux Journal: delivering readers the advice and inspiration they need to get the most out of their Linux systems since 1994.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Sans Direction's picture

Unicode

On September 7th, 2009 Sans Direction (not verified) says:

I was making a weather popup -- I work in a sub-basement and always want to know what things look like when I go up to ground level -- and I wanted to stick the degree symbol (°) with Unicode and got a circumflex capital A (°) first. Any idea. When I print the string to STDOUT, no problem. When it goes to notify, no dice. Perl, btw. Is there a Unicode-safe way of handling this?

Sans Direction's picture

Reply To Self

On September 8th, 2009 Sans Direction (not verified) says:

Not a notify-send issue. A Perl issue. See http://ahinea.com/en/tech/perl-unicode-struggle.html . Nevermind....

RyanE's picture

OSD

On September 3rd, 2009 RyanE (not verified) says:

I like osd_cat best myself.

AprilCoolsDay's picture

Some trick: (sleep 55m;

On September 3rd, 2009 AprilCoolsDay (not verified) says:

Some trick:

(sleep 55m; notify-send "Laundry Done!" -t 0) &

And you can use gmessage, zenity, kdialog instead too.

gmessage -center -nofocus -font 'Sans Bold 48' "Laundry Done"

zenity --warning --text="Laundry Done!"

kdialog --passivepopup "Laundry Done!"

from http://kldp.org/node/106625 (Korean)

Dom Delimar's picture

Debian systems and other tools?

On September 2nd, 2009 Dom Delimar says:

The binary is in package libnotify-bin on Debian systems.

However, it shows me that (IMHO) ugly (maybe GTK?) notification pop-up message in the lower right part of the screen, while my system tray is not there.

Is there any other similar tool? I'm using zenity to accomplish a similar thing. Even thought it's pretty powerful in options, I don't see it being able to show exactly where you want it on the screen, unless you want it in the middle of the screen. ;)

__________________________

domdelimar.com

Dom Delimar's picture

Re: other tools?

On September 2nd, 2009 Dom Delimar says:

Oh, I just realized there's kdialog which still shows somewhat ugly (IMHO) notifications on KDE3 but seems to integrate really nicely with KDE4. At least, on KDE3 that I know of, it allows you to position your notification wherever you wish on the screen. Nice.

__________________________

domdelimar.com

jroco's picture

Can send a notification to another Ubuntu ?

On September 2nd, 2009 jroco (not verified) says:

Hello,

Can I send a Pop-Up Notification to another PC with UBUNTU system.

Thanks a Lot.

Jonathan.

Twitter: jonathanroco

Niklas Herder's picture

Re: notification

On September 3rd, 2009 Niklas Herder (not verified) says:

If you have ssh and X forwarding enabled on the remote system, you can send a notification like this:

ssh -X user@remote.system DISPLAY=:0 notify-send "Hello there"

This assumes that user has an X session running on :0, of course.

Steven Bakker's picture

Re: notification

On September 3rd, 2009 Steven Bakker (not verified) says:

Note that the "-X" (X forwarding) is not necessary here. X forwarding is used for executing remote commands that have to display their X contents on the local display, i.e.: "ssh -X user@remote.system xterm" would attempt to execute "xterm" on "remote.system", while displaying on my local display (forwarding the X11 communications over the SSH connection), effectively giving me a shell on "remote.system". What you want is to execute a command (doesn't really matter where), and have it display on the remote system.

Given that,

ssh user@remote.system DISPLAY=:0 notify-send 'Hello there'

Would presumably work equally well, assuming that user has permissions to access the display at :0.

Not sure if libnotify/notification-daemon has any provisions for remote connections (if so, you'd expect something like "DISPLAY=remote.system:0 notify-send 'Hello there'" to work as well; I have little hopes in that regard, though).

jroco's picture

You forget something with

On September 4th, 2009 jroco (not verified) says:

You forget something with the quotes. That is the real command:

ssh -X user@remote.system DISPLAY=:0.0 'notify-send "Hello World!" '

Only with the notify command between quotes ssh works fine.

Regards,

JR.-

Post new comment

Please note that comments may not appear immediately, so there is no need to repost your comment.
The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <pre> <ul> <ol> <li> <dl> <dt> <dd> <i> <b>
  • Lines and paragraphs break automatically.

More information about formatting options

Newsletter

Each week Linux Journal editors will tell you what's hot in the world of Linux. You will receive late breaking news, technical tips and tricks, and links to in-depth stories featured on www.linuxjournal.com.
Sign up for our Email Newsletter

Tech Tip Videos

From the Magazine

December 2009, #188

If last month's Infrastrucuture issue was too "big" for you then try on this month's Embedded issue. Find out how to use Player for programming mobile robots, build a humidity controller for your root cellar, find out how to reduce the boot time of your embedded system, and if you're new to embedded systems find out the basics that go into one. You can also read about the Beagle Board, the Mesh Potato and a spate of other interestingly named items. And along with our regular columns don't miss our new monthly column: Economy Size Geek.


Read this issue