Announcement

Collapse
No announcement yet.

Using Kdialog in bash script. How to exit the script if one closes the Kdialog window?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    [SOLVED] Using Kdialog in bash script. How to exit the script if one closes the Kdialog window?

    I have a set of Service Menus for Dolphin that use Kdialog for pop-up actions and user input. I noticed when I have a Yes-No dialog box open, if I close it rather than responding Yes or No, the script does not exit - it continues to the next part of the script, which is a password prompt. If I close the password dialog, the script exits.

    Obviously, the desired action would be for the script to quit/exit when any Kdailog window is closed.

    Anyone know how to make this happen?

    Sample from a script:
    Code:
    if [[ $isreadonly = "true" ]]; then
        kdialog --title "READ-ONLY btrfs Subvolume."\
        --yesno "This folder is a READ-ONLY btrfs Subvolume.\n Would you like to change this Read-Only subvolume to Read-Write?"\
        --no-label "Yes, make it Read-Write"\
        --yes-label "No, leave it Read-Only"
    
    #close dialog silently
            if [[ "$?" = 0 ]]; then
                exit 0
            fi
        
        PASSWD="$(kdialog --password "This task requires SUDO access. Enter your password: ")"
    
    #allow cancel to exit cleanly
            if [[ -z "$PASSWD" ]]; then
                kdialog --passivepopup "Info action cancelled" 6
                exit 0
            fi
    ​
    ​
    So if I launch the command from the service menu and get the "kdailog --yesno..." window as above and close it by clicking on the "X" on the window titlebar, I still get the "kdialog --password..." window. But if I then close the password window, the script exits.

    It seems like I should be able to correct the behavior by re-writing this part and reversing the action:
    Code:
    #close dialog silently
            if [[ "$?" = 0 ]]; then
                exit 0
            fi
        ​

    Please Read Me

    #2
    OK, this seems to have worked;
    Code:
    #close dialog silently
    if [[ "$?" -eq 0 ]]; then
    continue
    else
    exit 0
    fi​
    Nope. Now it exits all the time even when I choose the action.

    EDIT: Oops! I used -eq (equal to) rather than -ne (NOT equal). NOW it works, lol
    Last edited by oshunluvr; Apr 21, 2024, 09:52 AM.

    Please Read Me

    Comment

    Working...
    X