LinuxCommandLibrary

zenity

Display graphical dialog boxes from shell scripts

TLDR

Display the default question dialog

$ zenity --question
copy

Display an info dialog displaying the text "Hello!"
$ zenity --info --text="[Hello!]"
copy

Display a name/password form and output the data separated by ";"
$ zenity --forms --add-entry="[Name]" --add-password="[Password]" --separator="[;]"
copy

Display a file selection form in which the user can only select directories
$ zenity --file-selection --directory
copy

Display a progress bar which updates its message every second and show a progress percent
$ [(echo "#1"; sleep 1; echo "50"; echo "#2"; sleep 1; echo "100")] | zenity --progress
copy

SYNOPSIS

zenity DIALOG_TYPE [DIALOG_OPTIONS] [GENERAL_OPTIONS]

Example:
zenity --info --text="Hello, Zenity!" --title="My First Dialog"
zenity --entry --text="Enter your name:" --width=300
zenity --file-selection --multiple --directory

PARAMETERS

--calendar
    Displays a calendar selection dialog.

--entry
    Displays a text entry dialog for user input.

--error
    Displays an error message dialog.

--file-selection
    Displays a file or directory selection dialog.

--info
    Displays an informational message dialog.

--list
    Displays a list dialog with selectable items.

--progress
    Displays a progress bar dialog.

--question
    Displays a question dialog, returning true/false.

--text=text
    Sets the main text/message for the dialog.

--title=title
    Sets the window title of the dialog.

--width=pixels
    Sets the dialog window width.

--height=pixels
    Sets the dialog window height.

--filename=path
    Sets the initial filename or directory for file selection.

--directory
    Allows selection of directories instead of files.

--multiple
    Allows selection of multiple files or items.

--timeout=seconds
    Sets a timeout after which the dialog closes automatically.

DESCRIPTION

zenity is a command-line tool that allows shell scripts and applications to interact with users graphically. It provides a simple way to create various common GTK+ dialog boxes, bypassing the need for complex GUI programming. These dialogs include information, error, warning, question, text entry, file selection, calendar, progress bars, list views, and forms.

As part of the GNOME project, zenity aims to empower script developers to add user-friendly graphical interfaces to their scripts without delving into graphical toolkit specifics. It outputs the user's choices or input to standard output (stdout), which can then be easily captured and processed by the script. This makes it an invaluable tool for creating interactive desktop scripts, automating tasks, or providing quick feedback to users.

CAVEATS

zenity relies on a graphical desktop environment and the GTK+ toolkit; it cannot be used in a pure terminal (TTY) environment. Its functionality is focused on common dialog types, offering less customization than direct GTK+ programming. User input and selections are sent to standard output, requiring scripts to parse this output, which can be complex for multi-line inputs or filenames with special characters. While convenient, launching zenity incurs GUI overhead, making it potentially slower for very frequent or trivial interactions compared to purely command-line alternatives.

STANDARD OUTPUT FOR SCRIPTING

One of zenity's core features is its use of standard output (stdout) to return user input or choices. For example, a selected filename from --file-selection, entered text from --entry, or 'True'/'False' from --question are printed to stdout. This design allows shell scripts to easily capture and process the results using command substitution (e.g., variable=$(zenity --entry)), enabling dynamic script behavior based on user interaction.

DESKTOP ENVIRONMENT INTEGRATION

zenity is tightly integrated with the user's desktop environment, particularly GNOME. This means dialogs inherit the system's GTK+ theme, ensuring a consistent look and feel. It also leverages desktop services, such as the notification daemon for --notification dialogs, providing a seamless user experience that is visually and functionally aligned with other native applications.

HISTORY

zenity emerged as part of the GNOME desktop environment, specifically designed to replace older, less flexible tools like gdialog. It was introduced around the GNOME 2.2 release in 2003, providing a modern, GTK+ based solution for adding simple graphical interactions to shell scripts. Its development has focused on maintaining ease of use while integrating well with the GNOME desktop's look and feel, making it a staple for creating user-friendly scripts on Linux systems.

SEE ALSO

Copied to clipboard