How can I easily create a GUI dialog with a bash script?

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.


for simple dialogs Yad or kdialog are indeed the most featureful. A complete GUI for bash, however, can only be done by two programs I know of:

gtkdialog (https://code.google.com/p/gtkdialog) will give you a full fledged frontend for single programs and is probably what you are looking for in the first place if yad turns out to be not enough for your needs.

The other one is gtkserver (http://www.gtk-server.org) which is a seperate running GUI-server. Your bash application can communicate with it by means of pipes, messages or TCP-sockets which is quite convenient if you are planning a complex setup of scripts/applications with a single central interface. I think that it will be a bit over the top for your current project :-)