loading...
Cover image for Building GUI for your shell script using zenity

Building GUI for your shell script using zenity

rafi993 profile image Rafi ・1 min read

Sometimes the shell scripts that you write asks questions to the user so that they could change the some default value. We usually do this as text input. But for values like date, file path etc.. it would be nice if you show a calendar or a file picker.

There is a really nice command called zenity. Which allows you to build simple GUI for your shell script. Making your shell script more user friendly.

Let's say you want user to select a date you can do

$ zenity --calendar

and it will return you selected date as string

Alt Text

and for a file selection you can simply do

$ zenity --file-selection

When your shell scripts finishes you can notify the user using

$ zenity --notification --text "script completed"

zenity can do much more and it is has been out there for a while and it is available for most Linux distributions and even for other OS like Mac and Windows (but you may need to install them separately)

Edit: You can look for more details about all the options that zenity provides by runinng

$ man zenity

Discussion

pic
Editor guide
Collapse
jrop profile image
Jonathan Apodaca

I use a similar (TUI-based) one called whiptail. It's nice for bootstrapping a new system :D

Collapse
rafi993 profile image
Rafi Author

It is really cool. I once came across dialog command which is similar to this. I wonder what other similar commands are out there for building UI.

Collapse
manishfoodtechs profile image
manish srivastava

Can you write more detailed usage. Nice for sharing

Collapse
rafi993 profile image
Rafi Author

since man pages of zenity

$ man zenity

has all other options described in detail I thought I would leave it rather than replicating it. But it would be nice to demonstrate zenity with some specific use-case in mind.