personal web log written by izabeera and dryobates

notify-send cron

Notify-send from cron

by dryobates

How to run notify-send from cron?

It took me some time to find out how to run notify-send from cron and display notification.

I have started with crontab entry like that:

* * * * * /usr/local/bin/notify-send -u critical "test"

It didn’t work. Searching on the internet showed that running X applications from cron is quite popular question. I have tried some of advices like setting up DISPLAY environment variable, setting access through xhost etc. Non of that worked. What I have end up was:

* * * * * DISPLAY=:0.0 PATH=/usr/local/bin /usr/local/bin/notify-send -u critical "test"

Simple, right? Only set PATH. But why? I gave full path to notify-send?! I think that notify-send need to see some of other X applications binary (maybe /usr/local/bin/X ?) which in FreeBSD are traditionally installed in /usr/local/bin/.

If you were curious why I need to run notify-send from cron look at my full crontab:

24 21 * * * /usr/local/bin/notify-send -u critical "Go sleep within 30 min!"
45 21 * * * /usr/local/bin/notify-send -u critical "Go sleep within 15 min!!"
58 21 * * * /usr/local/bin/notify-send -u critical "Sleep!!!"
06,11,14,16-59 22 * * * /usr/local/bin/slock
* 23 * * * /usr/local/bin/slock

Well... The worst enemy sits in ourselves :)

Jakub Stolarski. Software engineer. I work professionally as programmer since 2005. Speeding up software development with Test Driven Development, task automation and optimization for performance are things that focus my mind from my early career up to now. If you ask me for my religion: Python, Vim and FreeBSD are my trinity ;) Email: