Remote libnotify.

I think most Linux users might be used to libnotify by now, you’ve probably seen stuff like this;

libnotify

Appearing when you get an message in Pidgin or when you get a new email if you use cgmail.
Now if you have notify-send installed you can have some fun with this, for Ubuntu users just

apt-get install libnotify-bin

Now let’s test this baby out,

notify-send -i gtk-info "libnotify example" "An example of libnotify notification thingy."

And you should get a notification similar to the image above.
The parameters are fairly simple

notify-send -i

Already I guess you can see the possibilities, you can roll this into a bash script, use the python bindings directly in one of your programs or call the command via any language that supports calling external programs.

For me I don’t really have any programs running on my desktop machine that really needs notification, but I do have several scripts running on my MythTV box. What I’d like to for them to be able to push notifications on to my desktop machine.

Enter ssh. I already have ssh setup on my desktop and MythTV box so that I can ssh in and out without using passwords, so let’s test these out.

andrew@desktop:~ ssh mythtv
andrew@mythtv:~ ssh desktop
andrew@desktop:~ notify-send -i gtk-info 'test' 'test'
libnotify-Message: Unable to get session bus: dbus-launch failed to autolaunch D-Bus session: Autolaunch error: X11 initialization failed.

Hm, well to be expected. Running GUI programs on a remote machine requires a little more work, let’s try again.

andrew@desktop:~ DISPLAY=:0.0 notify-send -i gtk-info 'test' 'test'

If you still have problems at this point, check you are using the right value for DISPLAY variable.

andrew@desktop:~ xdpyinfo | grep 'name of display'
name of display: :0.0

If that looks o.k., then make sure that your X server is setup to allow remote connections from the machine you are going to use.

andrew@desktop:~ xhost +mythtv

or

andrew@desktop:~ xhost +192.168.0.10

And finally, hopefully things are working o.k. now so simply wrap the notify-send command into a ssh call.

andrew@mythtv:~ ssh desktop 'DISPLAY=:0.0 notify-send -i gtk-info "test subject" "test message"

Success!

The next step is to work out a who to push libnotify events to a laptop with a roving IP address.

No Comment

No comments yet

Leave a reply