# Manual de Zenity

Zenity Desktop Application Manual V2.0
2003
2004
Sun Microsystems, Inc.
Sun Microsystems, Inc.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License (GFDL), Version 1.1 or any later version published by the Free Software Foundation with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. You can find a copy of the GFDL at this link or in the file COPYING-DOCS distributed with this manual.

This manual is part of a collection of GNOME manuals distributed under the GFDL. If you want to distribute this manual separately from the collection, you can do so by adding a copy of the license to the manual, as described in section 6 of the license.

Many of the names used by companies to distinguish their products and services are claimed as trademarks. Where those names appear in any GNOME documentation, and the members of the GNOME Documentation Project are made aware of those trademarks, then the names are in capital letters or initial capital letters.

DOCUMENT AND MODIFIED VERSIONS OF THE DOCUMENT ARE PROVIDED UNDER THE TERMS OF THE GNU FREE DOCUMENTATION LICENSE WITH THE FURTHER UNDERSTANDING THAT:

1. DOCUMENT IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES THAT THE DOCUMENT OR MODIFIED VERSION OF THE DOCUMENT IS FREE OF DEFECTS MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY, ACCURACY, AND PERFORMANCE OF THE DOCUMENT OR MODIFIED VERSION OF THE DOCUMENT IS WITH YOU. SHOULD ANY DOCUMENT OR MODIFIED VERSION PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT THE INITIAL WRITER, AUTHOR OR ANY CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. NO USE OF ANY DOCUMENT OR MODIFIED VERSION OF THE DOCUMENT IS AUTHORIZED HEREUNDER EXCEPT UNDER THIS DISCLAIMER; AND

2. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, WHETHER IN TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE AUTHOR, INITIAL WRITER, ANY CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE DOCUMENT OR MODIFIED VERSION OF THE DOCUMENT, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO ANY PERSON FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR MALFUNCTION, OR ANY AND ALL OTHER DAMAGES OR LOSSES ARISING OUT OF OR RELATING TO USE OF THE DOCUMENT AND MODIFIED VERSIONS OF THE DOCUMENT, EVEN IF SUCH PARTY SHALL HAVE BEEN INFORMED OF THE POSSIBILITY OF SUCH DAMAGES.

Sun
Java Desktop System Documentation Team
Sun Microsystems, Inc.
Glynn
Foster
Projècte de documentacion de GNOME
Nicholas
Curran
Projècte de documentacion de GNOME
Zenity Desktop Application Manual V2.0
Agost de 2004

Sun Java Desktop System Documentation Team

Sun Microsystems, Inc.

Manual de Zenity 1.0
Genièr de 2003

Glynn Foster

Projècte de documentacion de GNOME

Aqueste manual descriu la version 2.6.0 de Zenity.

## Feedback

To send feedback, follow the directions in the Feedback Page.

Zenity is a rewrite of gdialog, the GNOME port of dialog which allows you to display dialog boxes from the commandline and shell scripts.

## Introduccion

Zenity enables you to create the following types of simple dialog:

- Calendièr

- Seleccion de fichièrs

- Tièra

- Icòna de notificacion

- Messatge

  - Error

  - Entresenhas

  - Question

  - Alèrta

- Avançament

- Text entry

- Text information

## Utilizacion

When you write scripts, you can use Zenity to create simple dialogs that interact graphically with the user, as follows:

- You can create a dialog to obtain information from the user. For example, you can prompt the user to select a date from a calendar dialog, or to select a file from a file selection dialog.

- You can create a dialog to provide the user with information. For example, you can use a progress dialog to indicate the current status of an operation, or use a warning message dialog to alert the user.

When the user closes the dialog, Zenity prints the text produced by the dialog to standard output.

When you write Zenity commands, ensure that you place quotation marks around each argument.

For example, use:

    zenity --calendar --title="Holiday Planner"

Do not use:

    zenity --calendar --title=Holiday Planner

If you do not use quotation marks, you might get unexpected results.

### Access Keys

An access key is a key that enables you to perform an action from the keyboard rather than use the mouse to choose a command from a menu or dialog. Each access key is identified by an underlined letter on a menu or dialog option.

Some Zenity dialogs support the use of access keys. To specify the character to use as the access key, place an underscore before that character in the text of the dialog. The following example shows how to specify the letter 'C' as the access key:

    "_Causissètz un nom".

### Exit Codes

Zenity returns the following exit codes:

Exit Code | Descripcion
--- | ---
`0` | The user has pressed either OK or Close.
`1` | The user has either pressed Cancel, or used the window functions to close the dialog.
`-1` | An unexpected error has occurred.
`5` | The dialog has been closed because the timeout has been reached.

### Opcions generalas

All Zenity dialogs support the following general options:

`--title`=títol

  Specifies the title of a dialog.

`--window-icon`=camin_de_l'icòna

  Specifies the icon that is displayed in the window frame of the dialog. There are 4 stock icons also available by providing the following keywords - 'info', 'warning', 'question' and 'error'.

`--width`=largor

  Specifies the width of the dialog.

`--height`=nautor

  Specifies the height of the dialog.

`--timeout`=timeout

  Specifies the timeout in seconds after which the dialog is closed.

### Opcions d'ajuda

Zenity provides the following help options:

`--help`

  Displays shortened help text.

`--help-all`

  Displays full help text for all dialogs.

`--help-general`

  Displays help text for general dialog options.

`--help-calendar`

  Displays help text for calendar dialog options.

`--help-entry`

  Displays help text for text entry dialog options.

`--help-error`

  Displays help text for error dialog options.

`--help-info`

  Displays help text for information dialog options.

`--help-file-selection`

  Displays help text for file selection dialog options.

`--help-list`

  Displays help text for list dialog options.

`--help-notification`

  Displays help text for notification icon options.

`--help-progress`

  Displays help text for progress dialog options.

`--help-question`

  Displays help text for question dialog options.

`--help-warning`

  Displays help text for warning dialog options.

`--help-text-info`

  Displays help for text information dialog options.

`--help-misc`

  Displays help for miscellaneous options.

`--help-gtk`

  Visualiza l'ajuda per las opcion GTK+.

### Miscellaneous Options

Zenity also provides the following miscellaneous options:

`--about`

  Displays the About Zenity dialog, which contains Zenity version information, copyright information, and developer information.

`--version`

  Displays the version number of Zenity.

### Opcions GTK+

Zenity supports the standard GTK+ options. For more information about the GTK+ options, execute the `zenity -?` command.

### Environment Variables

Normally, Zenity detects the terminal window from which it was launched and keeps itself above that window. This behavior can be disabled by unsetting the `WINDOWID` environment variable.

## Calendar Dialog

Use the `--calendar` option to create a calendar dialog. Zenity returns the selected date to standard output. If no date is specified on the command line, the dialog uses the current date.

The calendar dialog supports the following options:

`--text`=tèxt

  Specifies the text that is displayed in the calendar dialog.

`--day`=jorn

  Specifies the day that is selected in the calendar dialog. day must be a number between 1 and 31 inclusive.

`--month`=mes

  Specifies the month that is selected in the calendar dialog. month must be a number between 1 and 12 inclusive.

`--year`=annada

  Specifies the year that is selected in the calendar dialog.

`--date-format`=format

  Specifies the format that is returned from the calendar dialog after date selection. The default format depends on your locale. format must be a format that is acceptable to the `strftime` function, for example `%A %d/%m/%y`.

The following example script shows how to create a calendar dialog:

            #!/bin/sh

            if zenity --calendar \
            --title="Seleccionatz una data" \
            --text="Clicatz sus una data per la seleccionar." \
            --day=10 --month=8 --year=2004
              then echo $?
              else echo "Pas de data seleccionada"
            fi

### Calendar Dialog Example

Zenity calendar dialog example

## File Selection Dialog

Use the `--file-selection` option to create a file selection dialog. Zenity returns the selected files or directories to standard output. The default mode of the file selection dialog is open.

The file selection dialog supports the following options:

`--filename`=nom_de_fichièr

  Specifies the file or directory that is selected in the file selection dialog when the dialog is first shown.

`--multiple`

  Allows the selection of multiple filenames in the file selection dialog.

`--directory`

  Allows only selection of directories in the file selection dialog.

`--save`

  Set the file selection dialog into save mode.

`--separator`=separator

  Specifies the string that is used to divide the returned list of filenames.

The following example script shows how to create a file selection dialog:

            #!/bin/sh

            FILE=`zenity --file-selection --title="Select a File"`

            case $? in
                     0)
                            echo "\"$FILE\" selected.";;
                     1)
                            echo "No file selected.";;
                    -1)
                            echo "No file selected.";;
            esac

### File Selection Dialog Example

Zenity file selection dialog example

## Icòna de notificacion

`--text`=tèxt

  Specifies the text that is displayed in the notification area.

The following example script shows how to create a notification icon:

            #!/bin/sh

            zenity --notification\
              --window-icon="info" \
              --text="There are system updates necessary!"

### Exemple d'icòna de notificacion

Zenity notification icon example

## List Dialog

Use the `--list` option to create a list dialog. Zenity returns the entries in the first column of text of selected rows to standard output.

Data for the dialog must specified column by column, row by row. Data can be provided to the dialog through standard input. Each entry must be separated by a newline character.

If you use the `--checklist` or `--radiolist` options, each row must start with either 'TRUE' or 'FALSE'.

The list dialog supports the following options:

`--column`=colomna

  Specifies the column headers that are displayed in the list dialog. You must specify a `--column` option for each column that you want to display in the dialog.

`--checklist`

  Specifies that the first column in the list dialog contains check boxes.

`--radiolist`

  Specifies that the first column in the list dialog contains radio boxes.

`--editable`

  Autorizar la modificacion dels elements visualizats.

`--separator`=separator

  Specifies what string is used when the list dialog returns the selected entries.

`--print-column`=colomna

  Specifies what column should be printed out upon selection. The default column is '1'. 'ALL' can be used to print out all columns in the list.

The following example script shows how to create a list dialog:

            #!/bin/sh

            zenity --list \
              --title="Choose the Bugs You Wish to View" \
              --column="Bug Number" --column="Severity" --column="Description" \
                992383 Normal "GtkTreeView crashes on multiple selections" \
                293823 High "GNOME Dictionary does not handle proxy" \
                393823 Critical "Menu editing does not work in GNOME 2.0"

### List Dialog Example

Zenity list dialog example

## Message Dialogs

Zenity can create four types of message dialog:

- Error

- Entresenhas

- Question

- Alèrta

For each type, use the `--text` option to specify the text that is displayed in the dialog.

### Error Dialog

Use the `--error` option to create an error dialog.

The following example script shows how to create an error dialog:

              #!/bin/bash

              zenity --error \
              --text="Impossible de trobar /var/log/syslog."

#### Error Dialog Example

Zenity error dialog example

### Information Dialog

Use the `--info` option to create an information dialog.

The following example script shows how to create an information dialog:

              #!/bin/bash

              zenity --info \
              --text="Fusion acabada. 3 fichièrs sur 10 meses a jorn."

#### Information Dialog Example

Zenity information dialog example

### Question Dialog

Use the `--question` option to create a question dialog.

The following example script shows how to create a question dialog:

              #!/bin/bash

              zenity --question \
              --text="Are you sure you wish to proceed?"

#### Question Dialog Example

Zenity question dialog example

### Warning Dialog

Use the `--warning` option to create a warning dialog.

The following example script shows how to create a warning dialog:

              #!/bin/bash

              zenity --warning \
              --text="Disconnect the power cable to avoid electrical shock."

#### Warning Dialog Example

Zenity warning dialog example

## Progress Dialog

Use the `--progress` option to create a progress dialog.

Zenity reads data from standard input line by line. If a line is prefixed with #, the text is updated with the text on that line. If a line contains only a number, the percentage is updated with that number.

The progress dialog supports the following options:

`--text`=tèxt

  Specifies the text that is displayed in the progress dialog.

`--percentage`=percentatge

  Specifies the initial percentage that is set in the progress dialog.

`--auto-close`

  Closes the progress dialog when 100% has been reached.

`--pulsate`

  Specifies that the progress bar pulsates until an EOF character is read from standard input.

The following example script shows how to create a progress dialog:

            #!/bin/sh
            (
            echo "10" ; sleep 1
            echo "# Updating mail logs" ; sleep 1
            echo "20" ; sleep 1
            echo "# Resetting cron jobs" ; sleep 1
            echo "50" ; sleep 1
            echo "This line will just be ignored" ; sleep 1
            echo "75" ; sleep 1
            echo "# Rebooting system" ; sleep 1
            echo "100" ; sleep 1
            ) |
            zenity --progress \
              --title="Update System Logs" \
              --text="Scanning mail logs..." \
              --percentage=0

            if [ "$?" = -1 ] ; then
                    zenity --error \
                      --text="Update canceled."
            fi

### Progress Dialog Example

Zenity progress dialog example

## Text Entry Dialog

Use the `--entry` option to create a text entry dialog. Zenity returns the contents of the text entry to standard output.

The text entry dialog supports the following options:

`--text`=tèxt

  Specifies the text that is displayed in the text entry dialog.

`--entry-text`=tèxt

  Specifies the text that is displayed in the entry field of the text entry dialog.

`--hide-text`

  Hides the text in the entry field of the text entry dialog.

The following example script shows how to create a text entry dialog:

            #!/bin/sh

            if zenity --entry \
            --title="Add an Entry" \
            --text="Enter your _password:" \
            --entry-text "password" \
            --hide-text
              then echo $?
              else echo "No password entered"
            fi

### Text Entry Dialog Example

Zenity text entry dialog example

## Text Information Dialog

Use the `--text-info` option to create a text information dialog.

The text information dialog supports the following options:

`--filename`=nom_de_fichièr

  Specifies a file that is loaded in the text information dialog.

`--editable`

  Allows the displayed text to be edited. The edited text is returned to standard output when the dialog is closed.

The following example script shows how to create a text information dialog:

            #!/bin/sh

            FILE=`zenity --file-selection  \
              --title="Seleccionatz un fichièr"`

            case $? in
                     0)
                            zenity --text-info  \
                              --title=$FILE
                              --filename=$FILE  \
                              --editable 2>/tmp/tmp.txt;;
                     1)
                            echo "Pas de fichièr seleccionat.";;
                    -1)
                            echo "Pas de fichièr seleccionat.";;
            esac

### Text Information Dialog Example

Zenity text information dialog example