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

I found by chance it was possible to display a combo box with zenity (version tested: 2.32.1). See the following code:

#!/bin/bash
array=(a b c d e)
value=$(zenity --entry --title "Window title" --text "${array[@]}" --text "Insert your choice.")

The result is illustrated with the following 3 images:

enter image description here

enter image description here

enter image description here

I have two questions about that:

  1. Is there a documentation about this functionality? I didn't find anything in the zenity documentation.

  2. Why the first value of my array doesn't appear in the combo box? In the example above, my array is (a b c d e), and the combo box only displays b c d e.

    As a workaround, I add a value in my array, for example (0 a b c d e).

share|improve this question

2 Answers 2

up vote 3 down vote accepted

The first element of the array gets eaten up by --text. After expansion, your zentiy-line looks like:

zenity --entry --title "Window title" --text a b c d e --text "Insert your choice."
# Which zenity treats equivalent to
zenity --entry --title "Window title" --text a --text "Insert your choice." b c d e

So you first set the text to "a", then you override that with "Insert your choice." And the remaining arguments become the choices.

What you want is:

zenity --entry --title "Window title" --text "Insert your choice." a b c d e
# Hence:
zenity --entry --title "Window title" --text "Insert your choice." "${array[@]}"
share|improve this answer

See http://library.gnome.org/users/zenity/2.32/zenity.html#zenity-text-entry-options I think you want to use --text-entry for the array of values, not --text. Using:

#!/bin/bash
array=(a b c d e)
value=$(zenity --entry --title "Window title" --entry-text "${array[@]}" --text "Insert your choice.")

I see the default value of the dropdown box pre-filled with the first value of array, and all values available.

share|improve this answer
    
Thanks for the answer. It's curious that the manual does not refer to combo box. –  jpfleury Jul 5 '11 at 20:25

Your Answer

 
discard

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.