Search code examples
linuxzenity

How to close zenity window by press on Cancel button?


I have until loop and I can't get it how to break the loop when I click Cancel button? My until loop looks like this:

until [[ "$VAR" == "End" && **<second cond. for cancel>**  ]]; do
...

The problem is if I want to close the window I have to click on the red cross. If I want to do this with the "cancel" button, the window does not respond to it.

Tried to find the return value information after clicking cancel, and do an expression for that.

I wonder what the condition should be for it to work properly instead <second cond. for cancel>

SOLUTION: as someone said, <secound cond. for cancel> should be $? == 1. It works fine now.


Solution

  • Zenity exits with an exitcode of 1 if you press the cancel button (or close the dialog window, or press <Escape>). You could write something like this:

    #!/bin/bash
    
    rc=0
    until [[ $VAR == "End" || $rc == 1 ]]; do
        VAR=$(
            zenity --entry --text "Choose an action"
        )
    
        rc=$?
    done
    

    This loop will exit if you enter End in the text field, or if you press the Cancel button.