Ubuntu – How to easily create a GUI dialog with a bash script

bashcommand linescriptsyadzenity

I need to present some text along with the items(about 15 values) for each of two Bash list(file) records. On the same screen I need to present a three way selection, (buttons, scrolled selection window, etc.).

I'm an Ubuntu(11.04) scripting noob just beginning to use Zenity in scripts. My friends suggested YAD.

Can I do all of that in YAD or use some other easy GUI tool unknown to us?

.

Best Answer

Here's a very minimal implementation in Yad.

A textfile named 'mylist' in the same directory as the script contains "1 2 3 4 5 6 7 8 9 10". A space character is the default delimeter for input into lists.

The example script is:

#/bin/bash
thelist=$(<mylist)
thechoice=$(yad --title="Choose a value" --width=200 --height=200 --list --column="Values" --separator="" $thelist)
exit $(yad --title="You chose..." --text=$thechoice)

That's it. Scrolling the list is handled automatically. The --separator="" is to supress Yad's default of appending a pipe character ("|") to the output.

When you read the man page, you will see that you have a large array of possibilites. You can add buttons, icons, radio buttons, etc. You can create tabbed dialogs by using Yad's Notebook feature to embed dialogs within other dialogs as plugins.

There's a long example at PCLinusOS mag and some interesting shorter examples at the Yad site.

Related Question