12 August 2011

Sending desktop notifications from cron jobs.

I often use the notify-send command to create pop-up notifications on my desktop when things happen (usually when a time consuming job completes). Here's an example:

% do_stuff && notify-send "Done"

I started sticking lines like this in some cron jobs too, but for some reason it wasn't working. Then I discovered via this snippet on Command Line Fu that it's because cron doesn't run as a sub process of the desktop - hence it's not aware of your X session. This can be fixed, with a simple:

export DISPLAY=:0
export XAUTHORITY=~/.Xauthority
do_stuff && notify-send "done"

Nice!