Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: [SOLVED] zenity: Gtk-WARNING **: cannot open display

  1. #1
    Join Date
    Oct 2006
    Location
    North Texas, USA
    Beans
    11
    Distro
    Ubuntu 10.04 Lucid Lynx

    [SOLVED] zenity: Gtk-WARNING **: cannot open display

    Howdy!
    I'm using a script that is called by UDEV whenever I mount my USB thumb drive, which automatically makes a backup of the thumb drive. It works fine. I thought I'd add a question dialog using zenity, to ask the user (me) whether to skip the backup this time. My zenity question dialog works just fine when run from a test script on my desktop, but when added to the UDEV script (which I think runs as root) the zenity call gets this error message:
    (zenity:8596): Gtk-WARNING **: cannot open display:

    From reading posts here and thru Google, I think the script running as root doesn't have access to my xterm or GUI display, but here my knowledge runs out and I don't know how to fix that. I'm guessing maybe setting an environment variable at the beginning of my script, but I don't really know what variable or value.

    Anybody know how to fix this? (I'm using Hardy beta, with up-to-date updates).

    Thanks so much!
    Ubuntu rocks!
    ...Jeff

  2. #2
    Join Date
    Dec 2006
    Beans
    984
    Distro
    Xubuntu 8.04 Hardy Heron

    Re: zenity: Gtk-WARNING **: cannot open display

    Try running the script using sudo (or gksudo) with the -s option. For example:
    Code:
    sudo -s -u username script
    I'm not 100% certain if this will work, but I've always been able to run X applications whenever I use sudo -s.

    In order to avoid having to type a password, using /usr/sbin/visudo, add this to your sudoers file:
    Code:
    username ALL=(ALL) NOPASSWD:/path/to/script

    Take the risk of thinking for yourself, much more happiness, truth, beauty, and wisdom will come to you that way. --Christopher Hitchens

  3. #3
    Join Date
    Oct 2006
    Location
    North Texas, USA
    Beans
    11
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: zenity: Gtk-WARNING **: cannot open display

    Actually, I'm not running the script, it is being automatically run by the UDEV utility, which can be set up to run user supplied scripts when certain events take place, like when a thumb drive is mounted. It always runs its scripts as root, and I don't think I can change that. I think what's happening is that I've coded the script to throw up a message and wait for a reply (using zenity), but since the script is running as root, it doesn't know how to access my gui desktop, and so the message/reply fails. I'm thinking there must be something I need to add to the script so it knows how to access my gui display when it needs to.

  4. #4
    Join Date
    Dec 2006
    Beans
    984
    Distro
    Xubuntu 8.04 Hardy Heron

    Re: zenity: Gtk-WARNING **: cannot open display

    Inside the script try using sudo (or gksudo) to run zenity. See if this works:
    Code:
    sudo -u $USER zenity

    Take the risk of thinking for yourself, much more happiness, truth, beauty, and wisdom will come to you that way. --Christopher Hitchens

  5. #5
    Join Date
    Oct 2006
    Location
    North Texas, USA
    Beans
    11
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: zenity: Gtk-WARNING **: cannot open display

    That seemed like a really good idea, but unfortunately it didn't work. I tried both sudo and gksudo, and got the same error message. Thanks for the suggestion though!

  6. #6
    Join Date
    May 2007
    Location
    the Netherlands
    Beans
    647
    Distro
    Ubuntu Development Release

    Re: zenity: Gtk-WARNING **: cannot open display


  7. #7
    Join Date
    Dec 2006
    Beans
    984
    Distro
    Xubuntu 8.04 Hardy Heron

    Re: zenity: Gtk-WARNING **: cannot open display

    Try running
    Code:
    xhost local:user
    before gksudo. Where user is the name of the user you want to run as.

    Take the risk of thinking for yourself, much more happiness, truth, beauty, and wisdom will come to you that way. --Christopher Hitchens

  8. #8
    Join Date
    Oct 2006
    Location
    North Texas, USA
    Beans
    11
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: zenity: Gtk-WARNING **: cannot open display

    Thanks for that suggestion as well: I read the thread you sent me the link for, and I tried adding this to the script:

    export DISPLAY=:0.0

    It still doesn't work (zenity, that is), but now I get a new error message:

    No protocol specified

    in addition to the Gtk warning message I was getting before. Is that significant of something?

    Thank you for your time trying to help!

  9. #9
    Join Date
    Oct 2006
    Location
    North Texas, USA
    Beans
    11
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: zenity: Gtk-WARNING **: cannot open display

    I tried the xhost local:user -- still getting the same errors:

    No protocol specified

    (zenity:7522): Gtk-WARNING **: cannot open display: :0.0

  10. #10
    Join Date
    Oct 2006
    Location
    North Texas, USA
    Beans
    11
    Distro
    Ubuntu 10.04 Lucid Lynx

    Talking Re: zenity: Gtk-WARNING **: cannot open display

    Yippee! With a little repeated testing I finally got it to work, using a combination of the clues you good people have given me.
    Here's what I eventually coded in the script (which is executed by UDEV):

    Code:
    su $USER -c 'xhost local:$USER; zenity --question --text "Continue or cancel?" '
    I couldn't tell you WHY it works, but it does! Now when I plug in the USB thumb drive, the zenity question box appears and waits for an answer.

    Thanks to all who responded!
    Ubuntu Forums Rock!

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •