Skip to navigation

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.

One Response to “Running X apps (like zenity) from crontab (solving “cannot open display” problem)”

  1. man Says:

    Wow, thanks this was frustrating to get it working.

Leave a Reply