This site is now 100% read-only, and retired.

Creating shell script GUIs

Posted by Steve on Sat 15 Jan 2005 at 15:35

A few days ago I was upgrading my machine when I noticed a package name that I'd never noticed before - zenity. It's a simple program which allows you to create GUIs from shell scripts.

zenity is much like the dialog program which allows you to create menus, lists, and read input from the xterm, except it runs in X.

This allows you to create simple scripts which will prompt the user graphically for information, or show error messages.

For example if you wished a user to choose a date you could run this script:

#!/bin/sh
#
# Prompt the user for a date and save it
#
date=`zenity --calendar`

echo "You chose $date"

This invokes the zenity command, with the argument --calendar which causes it to display a calendar, allowing the user to choose a date.

If you don't have the program installed get it and test it out with these two commands:

apt-get install zenity
zenity --calendar

The calendar looks like this:

Sample calendar output

There are many other options you can choose for displaying different things, and prompting for input.

This simple script uses the file selection option, for example:

#!/bin/sh

file=`zenity  --title="Select a file to remove" --file-selection`

if [ -e $file ] ; then
  echo "Removing $file"
  rm -f "$file"
else
  zenity --warning --text="File doesn't exist"
fi

Other operations such as displaying text files, asking questions, and showing progress bars are possible.

Running the following command will give you the supported options:

zenity --help

All of these are documented in the manpage which you can view with:

man zenity

 

 


Re: Creating shell script GUIs
Posted by Anonymous (49.201.xx.xx) on Thu 27 Oct 2011 at 13:53
Thou art awesome, you really have found a great tool.GUI via shell script is a dream came true.

[ Parent ]