Find the answer to your Linux question:
Results 1 to 4 of 4
Hello! I've written a script that includes Zenity. It prompts the user with a dialog box with a radiolist asking what the user wants the script to do, A or ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jul 2013
    Posts
    3

    Question Zenity: process continues even after clicking cancel


    Hello!

    I've written a script that includes Zenity. It prompts the user with a dialog box with a radiolist asking what the user wants the script to do, A or B with A selected as default. The script also has an OK button and a Cancel button. When I run the script and the dialog box opens, I select A, it performs A, and if I select B, it performs B. But when I hit cancel, instead of just exiting the script, it performs A(default). Does anyone know what code I should add to have the script exit when the user clicks on cancel? Thank you!

  2. #2
    Trusted Penguin
    Join Date
    May 2011
    Posts
    4,353
    hi,

    can you post your code? you're much more likely to get responses if you do.

  3. #3
    Just Joined!
    Join Date
    Jul 2013
    Posts
    3
    Hi atreyu,

    Sure, here is the code. Thanks!

    -----------------------

    Code:
    #!/bin/sh
    
    ldm=`zenity --list \
    --title="Normal or Severe Ops?" \
    --text="Normal or Severe Ops?" \
    --radiolist \
    --column="" --column="Map Type" TRUE "Normal" FALSE "Severe"`
    
    if [ "$ldm" == "Severe" ]; then
    
    echo "$ldm"
    ssh ldm@ls1 cp /ldad/localapps/ldm/severe/ldmd.conf /usr/local/ldm/etc
    ssh -X ldm@ls1 /ldad/localapps/ldm/restartldm.sh 2>&1 | zenity --text-info --title "Restarting the LDM" --width 600 --height 300
    
    else
    
    echo "$ldm"
    ssh ldm@ls1 cp /ldad/localapps/ldm/normal/ldmd.conf /usr/local/ldm/etc
    ssh -X ldm@ls1 /ldad/localapps/ldm/restartldm.sh 2>&1 | zenity --text-info --title "Restarting the LDM" --width 600 --height 300
    
    fi
    
    exit
    Last edited by MikeTbob; 08-02-2013 at 12:25 PM. Reason: added code tags

  4. #4
    Penguin of trust elija's Avatar
    Join Date
    Jul 2004
    Location
    Either at home or at work or down the pub
    Posts
    3,569
    I'm not really a bash scripter but the following does work.

    If you think about the flow then when cancel is pressed, ldm will not be equal to "Severe" so it will drop in to the else clause. Adding another test for ldm being equal to "Normal" will stop the code running when cancel is pressed. You could achieve the same with a single elif but I will leave that as an exercise

    Code:
    #!/bin/sh
    
    ldm=`zenity --list \
    --title="Normal or Severe Ops?" \
    --text="Normal or Severe Ops?" \
    --radiolist \
    --column="" --column="Map Type" TRUE "Normal" FALSE "Severe"`
    
    if [ "$ldm" = "Severe" ]; then
    
        echo "$ldm"
        ssh ldm@ls1 cp /ldad/localapps/ldm/severe/ldmd.conf /usr/local/ldm/etc
        ssh -X ldm@ls1 /ldad/localapps/ldm/restartldm.sh 2>&1 | zenity --text-info --title "Restarting the LDM" --width 600 --height 300
     
    else
    
        if [ "$ldm" = "Normal" ]; then
            echo "$ldm"
            ssh ldm@ls1 cp /ldad/localapps/ldm/normal/ldmd.conf /usr/local/ldm/etc
            ssh -X ldm@ls1 /ldad/localapps/ldm/restartldm.sh 2>&1 | zenity --text-info --title "Restarting the LDM" --width 600 --height 300
        fi
    
    fi
    
    exit
    Last edited by elija; 08-02-2013 at 12:27 PM. Reason: Fix == bug in comparisons
    What do we want?
    Time machines!

    When do we want 'em?
    Doesn't really matter does it!?


    The Fifth Continent

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •