4

I want to write shell script file that has a GUI with multiple input boxes for user entry. I already tried zenity. Any ideas or advice would be appreciated.

Kazark
  • 698
moata_u
  • 5,413

5 Answers5

13

Yad may be useful in this regard, it is a fork of zenity with more features, one of them the ability to create forms.

Here is a very simple example of a form:

#!/bin/bash


frmdata=$(yad --title "Test Form" --form --field "Address" --field="Name")


frmaddr=$(echo $frmdata | awk 'BEGIN {FS="|" } { print $1 }')
frmname=$(echo $frmdata | awk 'BEGIN {FS="|" } { print $2 }')

echo $frmaddr > test.txt
echo $frmname >> test.txt

The above script will display a form like this:

Yad Form Example

After you enter your data and click ok or hit enter on the keyboard, the form data will be written to a text file called test.txt, I am using awk to separate the form data which is a string with a pipe as field separator, I believe there is a direct way to get the data without awk but I am no yad expert, please check the project home and ask questions, you may find a more elegant way.

How to get and install yad here:

http://www.webupd8.org/2010/12/yad-zenity-on-steroids-display.html

yad project home:

http://code.google.com/p/yad/

more examples here:

http://technostripe.com/yad-a-fork-of-zenity-with-more-features/

http://code.google.com/p/yad/wiki/Examples

I am late here but this may still be helpful.

Sabacon
  • 40,058
3

My response might be late (two years late I think) but since a lot of people still searching for the answer to this same question it might be useful. I also search for a "better than zenity/yad/xdialog" solution and I found two very good programs:

  1. gtkdialog: http://code.google.com/p/gtkdialog/ you can build a complete user interface for bash that keeps running while communicating with your backendscript. It is in active developement and is also used by puppy developers. it's own glade-like language is more powerful than libglade, it can run libglade XML however.

  2. gtkserver: http://www.gtk-server.org/ This one goes even a step further and runs as a coprocess while communicating with your bash script via pipes, messages or TCP-ports. It does not work with a XML-typed description file but with GTK-commands that you invoke from the bash commandline. Very powerful indeed :-)

gtkdialog is not in the repositories anymore but you can fins the latest versions in a PPA (https://launchpad.net/~dnjl/+archive/build/+sourcepub/2986274/+listing-archive-extra)

gtkserver has no PPA or deb AFAIK so this has to be compiled from source.

thom
  • 7,542
3

xDialog is something similar, here is a search list from freshmeat. tcl/tk is another, popular tool for such jobs.

A poor solution would need the user to fill a list, and finally mark all rows:

zenity --list --text "Fill every row, and mark all rows before hitting 'OK'" --column "title" --print-column=2 --multiple --column "value" --editable "name" "(please override)" "host" "" "ip" ""

I admit, that that's not comfortable.

user unknown
  • 6,507
1

You may want to try CommandUI. It does not require coding.

1

One solution would to use Zenity, but just display each prompt individually. The first prompt would be for the first field, and then when the user clicks "Ok", you could prompt for the second field.

It sounds like you might be reaching the limits of scripting, and might want to look into developing an application-like interface using something like QT or GTK.

Windigo
  • 1,167
  • @Windigo...QT or GTK that's what am thinking about..,but learning curve much more that other's like Zenity – moata_u Mar 20 '11 at 16:37