Building GUI for your shell script using zenity

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

This post is also available on DEV.