My father asked me how to setup an alert to remind him of the evening news. (The serious ones in the public channel, not the sensational in the private channels…)

My first suggestion was to use evolution, but it cluttered his calendar view. I guess you could avoid that by using a separate calendar file, though.

Still, these alerts are of very low priority, so I considered that the new notifications should actually suit better.

Sending notifications from the command line is supposedly easy - if you’re in the same session. Otherwise, you have to find out which socket to send it to. (Btw: what happens when the dbus daemon is restarted ungracefully? will notifications be broken until the session is restarted, too?)

Anyway, here’s the solution I came up with:

#!/bin/sh
user=`whoami`
pids=`pgrep -u whoami gnome-session`
title="$1"
text="$2"

for pid in $pids; do
        # find DBUS session bus for this session
        DBUS_SESSION_BUS_ADDRESS=`grep -z DBUS_SESSION_BUS_ADDRESS \
           /proc/$pid/environ | sed -e 's/DBUS_SESSION_BUS_ADDRESS=//'`
        # use it
        DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS \
           notify-send -u low -t 30000 "$title" "$text"
done

This will send a notification with a lifetime of 3 minutes to all running gnome-sessions of the current user. Supposedly works fine from cron (not yet tested, though). Error handling isn’t perfect yet, either (but again, this is a very low priority notification).

P.S. hint of the day: use a line like

apt-get install libnotify-bin && notify-send 'Yay! Completed!'

To get a fancy notification when your long-running process of the day is completed. Sweet.