Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Example script error.sh:

#! /bin/bash

zenity --error --text='Something very bad has happened!'  

My incron-config:

~/Documents IN_MOVED_TO ~/scripts/error.sh

If I run error.sh in terminal GUI dialog pops, but not in above incron scenario.

How can I make zenity to pop that dialog when I move file in Documents folder?

share|improve this question

2 Answers 2

Found answer here: link

add to ~/.bashrc:

xhost local:YOUR_USERNAME > /dev/null

and then use zenity in script evoked by cron like this:

zenity --error --text='Something very bad has happened!' --display=:0.0

adding --display=:0.0 is what's important

share|improve this answer

There's another possible solution if you want it to work regardless of username, by finding the active user of the X display, using ConsoleKit (the command ck-list-sessions). Assuming the below script is run as root, it will show a zenity message to the current active user on your computer:

ACTIVE=$(ck-list-sessions | awk -F' = ' '
    function f(){if(A=="TRUE"){P=U"\t"D;gsub("'"'"'","",P);print P}}
    END{f()} /^[^\t]/{f()}
USERID=${ACTIVE%    *} # tab
USERNAME=$(getent passwd $USERID|cut -f1 -d':')
DISPLAY=${ACTIVE#*  } # tab

DISPLAY="$DISPLAY" su $USERNAME -c "zenity --error --text='Something very bad has happened!'"

The little awk script is just for parsing ck-list-sessions and outputting the username and display of the user that is active (could also require that it's a local connection if you want to exclude ssh -X users, if you want).

(I use this in a backup script that runs on plugging in a USB drive.)

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.