6

Zenity annoys me by always displaying the warning in terminal:

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

Apparently I'm not the only one:

Almost all the answers tell you to change the way you call zenity by appending 2>/dev/null to the end of the command. I don't want to do this to all the code I've already written and remember this for future code I write.

Is there an easier way of making this annoying message disappear?

Sergiy Kolodyazhnyy
  • 103,293
  • 19
  • 273
  • 492
WinEunuuchs2Unix
  • 99,709
  • 34
  • 237
  • 401

3 Answers3

6

Automatically add 2>/dev/null every time zenity is called

Edit the file ~/.bashrc and search for these lines:

# some more ls aliases
alias ll='ls -alF'
alias la='ls -A'
alias l='ls -CF'

Add the following lines after:

# Add zenity alias to make the annoying terminal error message disappear forever:
# "Gtk-Message: GtkDialog mapped without a transient parent. This is discouraged."
alias zenity="zenity 2>/dev/null"

Save the file and open a new terminal window to test:

zenity --info --text "Hello Zenity-Silly-Error-Free World"

Voila! All your old code is fixed and future code doesn't need to have 2>/dev/null appended to it like all the other answers instruct.

WinEunuuchs2Unix
  • 99,709
  • 34
  • 237
  • 401
  • Why would you use sudo powers to edit your own bashrc? – Andrea Lazzarotto Mar 26 '17 at 01:55
  • @AndreaLazzarotto fixed that ;) – Sergiy Kolodyazhnyy Mar 26 '17 at 01:58
  • "...future code doesn't need to have 2>/dev/null appended to it like all the other answers instruct". Well, it still effectively has redirection appended to it each time, you just don't do it by hand. – Sergiy Kolodyazhnyy Mar 26 '17 at 02:02
  • 1
    @AndreaLazzarotto You are so right. Sorry my mind has been conditioned to put `sudo` into all my posts. Bad habits are hard to break... – WinEunuuchs2Unix Mar 26 '17 at 02:16
  • Simple and effective. I like it. – Elder Geek Sep 07 '17 at 22:50
  • @ElderGeek Thanks for the compliment. Should I accept my answer over Serg's then? I was waiting for input to recuse myself. – WinEunuuchs2Unix Sep 07 '17 at 23:10
  • That's your call, not mine. It looks like your answer preceded his, both answers have value. – Elder Geek Sep 07 '17 at 23:16
  • @ElderGeek Mine proceeds his only because I posted both the question and answer at the same time making it unfair. I'll wait to see how others vote and accept the most popular. Right now it appears tied although I did upvote his answer :) – WinEunuuchs2Unix Sep 07 '17 at 23:26
  • As did I so. IMHO your answer is more useful for the average user and his is more useful for those who program and recognize a function/method when they see one. – Elder Geek Sep 08 '17 at 00:11
  • 1
    In bash, aliases are not evaluated except when called in response to user command input or by using special shell variables, nor is .bashrc sourced when executed from a script (non-interactively). Since the primary use of zenity is scripting, this answer doesn't make a lot of sense to me. – Andrew Domaszek May 17 '19 at 12:44
  • @AndrewDomaszek Thanks for pointing this out. I've changed the accepted answer from my own to Serge. I should have done it two years ago when Elder Geek commented. – WinEunuuchs2Unix May 17 '19 at 13:02
  • @ElderGeek Thank you for your comments I've FINALLY acted upon them and changed accepted answer :) – WinEunuuchs2Unix May 17 '19 at 13:03
  • I don't see the reason why you would put it below the ls-aliases. It's not affected by them, nor does it affect those. Where is the relation? The alias would be as fine in the second line or the last line, wouldn't it? – user unknown Jan 30 '20 at 10:59
  • @userunknown I prefer to put user aliases below system aliases. Functionally it makes no difference but from a maintenance point of view and porting to new installs, I like to keep installation code above and custom code below. – WinEunuuchs2Unix Jan 31 '20 at 00:37
  • These aren't system aliases, since they are in the users .bashrc file. It's just a default suggestion. To have a system how to organize your aliases (some keep all of them in a separate file) is fine and I wouldn't suggest changing your habit. But a newbie can't infer that from your answer and might think there is some importance to this, that there is an effect. Ha, I just wanted to point out, that the TO, which is WinEunuuchs2Unix, seems not to need such advice with his high reputation, but that's you too. :) OK - keep the good work going. – user unknown Jan 31 '20 at 01:40
  • @userunknown Answer was written when reputation was low and I was still a relative beginner in Ubuntu/Linux.. By "system alias" I mean the Ubuntu installation created the alias. As far as new users go if they are keen enough they will read your comments to gain a greater understanding. If they do not read your comments and place alias where answer suggests no harm will come about. – WinEunuuchs2Unix Jan 31 '20 at 03:16
6

Update 2019-05-17: OP has found another resolution along the same method presented here via global redirection by use of exec command. Please refer to linked duplicate post for more info

Basically, there's no other way except redirecting stderr to /dev/null. The main reason is because Gtk requires dialog windows ( which is what zenity windows actually are ) to have a parent application window. This same thing happens if you build GUI dialog from scratch in c or python.

Thus, the only "real" way is for Gtk developers to actually allow dialog windows to stand on their own, or zenity developers to silence those warning from within their source code. Otherwise, your only option is to constantly add 2>/dev/null to any zenity command. Of course you can always make an alias or wrapper function that will do it for you, something along the lines of this:

zenity(){
    /usr/bin/zenity "$@" 2>/dev/null
}

This, however, may have issues with quoting and passing arguments, but for the most part should work. If you work in Python or another language that can actually handle Gtk, you can brew your own popup dialogs with hidden parent windows, which comes at the cost of complexity and learning how to create those things. But again, the real way would be for zenity developers actually fix this or Gtk developers to acknowledge the need for standalone dialog windows.

Sergiy Kolodyazhnyy
  • 103,293
  • 19
  • 273
  • 492
3

I prefer to edit ~/.bashrc with:

alias zenity="zenity 2> >(grep -v 'GtkDialog' >&2)"

This is more restrictive, inhibits only the warning messages that have the GtkDialog string, leaving the other error or warning messages to be displayed

Julio N
  • 41
  • 1
  • It works! The only problem is that another warning is generated in Ubuntu 18.04: `(zenity:6984): GLib-WARNING **: 14:59:39.494: ../../../../glib/giounix.c:410Error while getting flags for FD: Bad file descriptor (9)` – f0nzie Feb 12 '20 at 21:01