I am using Arch Linux with KDE/Awesome WM. I am trying to get notify-send to work with cron but no luck so far. I have tried every suggestion in online forums from setting DISPLAY/XAUTHORITY variables to running notify-send with "sudo -u" but no dice so far. I am able to call notify-send interactively from the session and get notifications. FWIW, the cron job is running fine which I verified by echoing stuff to a temporary file. It is just the "notify-send" that fails to work.
Code:
[matrix@morpheus ~]$ crontab -l
* * * * * /home/matrix/scripts/notify.sh
[matrix@morpheus ~]$ cat /home/matrix/scripts/notify.sh
#!/bin/bash
export DISPLAY=127.0.0.1:0.0
export XAUTHORITY=/home/matrix/.Xauthority
echo "testing cron" >/tmp/crontest
sudo -u matrix /usr/bin/notify-send "hello"
echo "now tested notify-send" >>/tmp/crontest
[matrix@morpheus ~]$ cat /tmp/crontest
testing cron
now tested notify-send
[matrix@morpheus ~]$
As you can see the echo before & after notify-send worked. Also I have tried setting DISPLAY=:0.0 Any help would be much appreciated UPDATE: Ok, So I searched a bit more and found that DBUS_SESSION_BUS_ADDRESS needs to be set. And after hardcoding this using the value I got from my interactive session, the tiny little "hello" message started popping up on the screen every minute!! WOOHOO! But the catch is this variable is not permanent per that post, so I'll have try the the named pipe solution suggested there.
[matrix@morpheus ~]$ cat scripts/notify.sh
#!/bin/bash
export DISPLAY=127.0.0.1:0.0
export XAUTHORITY=/home/matrix/.Xauthority
export DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-BouFPQKgqg,guid=64b483d7678f2196e780849752e67d3c
echo "testing cron" >/tmp/crontest
/usr/bin/notify-send "hello"
echo "now tested notify-send" >>/tmp/crontest
[matrix@morpheus ~]$
Meanwhile if anybody do know of any alternative method, please do post. Also since cron doesn't seem to support notify-send(atleast directly) is there some other notification system that is more cron friendly that I can use? Thanks.
&>>/tmp/crontest
to the notify send line and see ifnotify-send
gives any error messages. – Graeme yesterday