Building GUI for your shell script using zenity
Rafi

Rafi @rafi993

About: I'm a developer who works mostly with Javascript.

Joined:
Feb 19, 2018

Building GUI for your shell script using zenity

Publish Date: Aug 7 '20
34 4

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
Enter fullscreen mode Exit fullscreen mode

and it will return you selected date as string

Alt Text

and for a file selection you can simply do

$ zenity --file-selection
Enter fullscreen mode Exit fullscreen mode

When your shell scripts finishes you can notify the user using

$ zenity --notification --text "script completed"
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Comments 4 total

  • manish srivastava
    manish srivastavaAug 7, 2020

    Can you write more detailed usage. Nice for sharing

    • Rafi
      RafiAug 7, 2020

      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.

  • Jonathan Apodaca
    Jonathan ApodacaAug 7, 2020

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

    • Rafi
      RafiAug 8, 2020

      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.

Add comment