Running X apps (like zenity) from crontab (solving “cannot open display” problem)
I’ve written a small script that checks whether I have queued mail and that displays a notification icon via “zenity –notification” in case I do. I wanted to run it using ~/.crontab but it wouldn’t run. First, I got error messages from the cron daemon that looked like this:
(zenity:22981): Gtk-WARNING **: cannot open display:
Sure, I hadn’t specified a display. So I tried setting the DISPLAY explicitly in my ~/.crontab:
* * * * export DISPLAY=:0.0 && /path/to/checklog
but then I got:
No protocol specified (zenity:24101): Gtk-WARNING **: cannot open display: :0
The same happened when I tried running other X apps, like audacious. A line in ~/.crontab like this:
* * * * * DISPLAY=:0 /usr/bin/audacious
resulted in errors like this:
No protocol specified /usr/bin/audacious: Unable to open display, exiting.
It turns out I needed to set, in my ~/.bashrc:
xhost local:mpromber > /dev/null
to allow crontab access to my X display. It now works, either using “export DISPLAY=:0.0″ in the ~/.crontab, or alternatively just using
zenity --notification --display=:0.0
in the script that checks for queued mail.
March 18th, 2010 at 10:41
Wow, thanks this was frustrating to get it working.
November 4th, 2010 at 14:00
[...] [...]
November 4th, 2010 at 14:10
Hi, in reply to the latest pingback (comment #2; I’m not signed up to the forum it links to) — what exactly doesn’t work for you? Note that “mpromber” in this line
is my username, so you’d have to substitute your username.
August 18th, 2011 at 19:20
YOU ARE THE BEST ONE
September 1st, 2011 at 16:53
Yeah! Thanks a lot! It really works!
October 20th, 2011 at 20:24
Thanks a lot – I stumbled about this problem, too.