1

I'm trying to create a background bash script which creates a popup in certain circumstances, however, my code only works when run manually in a terminal (e.g. not in the background). I've tried various things such as:

screen env DISPLAY=:0.0 su $USER -c 'zenity --warning --text "Warning message here"'

Or

screen zenity --warning --text "Warning message here"

I've spent hours trying various different things, and I feel like there must be a simple solution and I'm just missing something.

Nothing I've tried works while the script is run in the background with cron.

I'm running Lubuntu 12.04, LXDE.

Any ideas to why I can't get it working?

migrated from stackoverflow.com Feb 3 '14 at 21:58

This question came from our site for professional and enthusiast programmers.

1

I had a similar problem before, when I checked $DISPLAY, I noticed that it had nothing, so I had to set it, and also I had to use xhost + to allow the message to pop-up.

Try the following command option to set the display:

xhost +
zenity --warning --text "Warning message here" --display="yourmachine:0.0"
  • It still doesn't work for me, unfortunately. Any other ideas? – user2370602 Jan 29 '14 at 15:17
  • 1
    Never mind, I've found the problem. I was running my script as root, but because I was logged in as a standard user the popup wasn't shown. (I suppose this is to stop other peoples popups appearing if there's more than one user logged in) – user2370602 Jan 29 '14 at 15:52
1

Looks like OP solved it, but I had the same basic question so here's a quick solution for anyone else. When running as a background process the following error is produced:

Gtk-Message: GtkDialog mapped without a transient parent. This is discouraged.

I am running zenity in a script via the at -f script.sh command, so the environment variable $DISPLAY needs to be set before running the command:

env DISPLAY=:0.0 zenity --warning --text "TIME TO CLOCKOUT!"

Now it works.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy