How to use notify-send with crontab? [duplicate]

As suggested by @Lnux:

Create a .sh, for example test.sh:

#!/bin/sh
eval "export $(egrep -z DBUS_SESSION_BUS_ADDRESS /proc/$(pgrep -u $LOGNAME gnome-session)/environ)";

#Code:
DISPLAY=:0 notify-send "Test"

Then set up crontab:

crontab -e

And at the bottom, add:

* * * * * /home/myUser/test.sh

Obs.: you can place your .sh file in another location and don't forget to allow executing it.


Crontab is running in the background and without specified graphical output it will show nothing. So you should spicify, which output would you like to use. To achieve that, put export DISPLAY=:0 && before you command, e.g.

15 * * * * export DISPLAY=:0 && notify-send 'I am alive!'