KDialog
- Some examples use HTML <br> tags. You could use \n in a few of them instead of the <br> tags, but since not all of them accept it, it’s not demonstrated below.
- Many examples use the old and new command substitution to combine commands. It isn’t always necessary to do so, and when it’s possible to achieve the same result without command substitution, other examples are shown.
- Most examples use the Bash echo command as the action taken.
Checklist
Each item in the list needs a key that is used by the script to identify which list items were chosen, a label that is used to communicate the choices to the user, and a setting to let the Kdialog command know whether to set the list item as selected when the list loads. In the examples below, numbers are used as the key to identify each list item, but you can use lower or upper case alphabet letters, words, or a combination of letters and numbers. Whatever you use will be what the script looks for to decide what to do.
- Example 1:
-
#!/bin/bash ############################################################################## # This script opens a Kdialog window with a single-line message that offers # # you a combo box from which to make a choice. When you make the choice, # # command substitution is used to save your choice to a variable that is # # used to determine which of the six possible messages to display in the # # terminal window based on which choice you make or whether you make one at # # all. # # # # The combo box returns 0 if the Enter key or the OK button is pressed. In # # that case, the script executes the action you assigned to 0 - in this # # example it echos the number or numbers (each surrounded in "quotes" with a # # space between them) you chose to the terminal window. # # # # The combo box returns 1 if the Esc key or Cancel button is pressed. In # # that case, the combo box bypasses the choices in the combo box and chooses # # to take the action in the else section - in this example it echos YOU # # CHOSE CANCEL to the terminal window. # # # # If anything else happens, the script executes the action you assigned to # # the else section - in this example it echos ERROR to the terminal window. # ############################################################################## variable=`kdialog --checklist "CHOOSE:" 1 "RED" on 2 "BLUE" off 3 "GREEN" off;`; if [ "$?" = 0 ]; then echo "$variable"; elif [ "$?" = 1 ]; then echo "YOU CHOSE CANCEL"; else echo "ERROR"; fi;
- Example 2:
-
#!/bin/bash ############################################################################## # This script opens a Kdialog window with a single-line message that offers # # you a combo box from which to make a choice. When you make the choice, # # command substitution is used to save your choice to a variable that is # # used to determine which of the six possible messages to display in the # # terminal window based on which choice you make or whether you make one at # # all. # # # # The combo box returns 0 if the Enter key or the OK button is pressed. In # # that case, the script executes the action you assigned to 0 - in this # # example it echos the number or numbers (each surrounded in "quotes" with a # # space between them) you chose to the terminal window. # # # # The combo box returns 1 if the Esc key or Cancel button is pressed. In # # that case, the combo box bypasses the choices in the combo box and chooses # # to take the action in the else section - in this example it echos YOU # # CHOSE CANCEL to the terminal window. # # # # If anything else happens, the script executes the action you assigned to # # the else section - in this example it echos ERROR to the terminal window. # ############################################################################## variable=$(kdialog --checklist "CHOOSE:" 1 "RED" on 2 "BLUE" off 3 "GREEN" off;); if [ "$?" = 0 ]; then echo "$variable"; elif [ "$?" = 1 ]; then echo "YOU CHOSE CANCEL"; else echo "ERROR"; fi;
- Example 3:
-
#!/bin/bash ############################################################################## # This script opens a Kdialog window with a two-line message (created by # # using an HTML <br> tag) that offers you a combo box from which to # # make a choice. When you make the choice, command substitution is used to # # save your choice to a variable that is used to determine which of the six # # possible messages to display in the terminal window based on which choice # # you make or whether you make one all. # # # # The combo box returns 0 if the Enter key or the OK button is pressed. In # # that case, the script executes the action you assigned to 0 - in this # # example it echos the number or numbers (each surrounded in "quotes" with a # # space between them) you chose to the terminal window. # # # # The combo box returns 1 if the Esc key or Cancel button is pressed. In # # that case, the combo box bypasses the choices in the combo box and chooses # # to take the action in the else section - in this example it echos YOU # # CHOSE CANCEL to the terminal window. # # # # If anything else happens, the script executes the action you assigned to # # the else section - in this example it echos ERROR to the terminal window. # ############################################################################## variable=$(kdialog --checklist "LINE1<br>LINE2" 1 "RED" on 2 "BLUE" off 3 "GREEN" off;); if [ "$?" = 0 ]; then echo "$variable"; elif [ "$?" = 1 ]; then echo "YOU CHOSE CANCEL"; else echo "ERROR"; fi;
- Example 4:
-
#!/bin/bash ############################################################################## # This script opens a Kdialog window with a single-line message that offers # # you a combo box from which to make a choice. When you make the choice, # # command substitution is used to save your choice to a variable that is # # used to determine which of the six possible messages to display in the # # terminal window based on which choice you make or whether you make one at # # all. # # # # The combo box returns 0 if the Enter key or the OK button is pressed. In # # that case, the script executes the action you assigned to 0 - in this # # example it echos the number or numbers you chose to the terminal window, # # each on a separate line. # # # # The combo box returns 1 if the Esc key or Cancel button is pressed. In # # that case, the combo box bypasses the choices in the combo box and chooses # # to take the action in the else section - in this example it echos YOU # # CHOSE CANCEL to the terminal window. # # # # If anything else happens, the script executes the action you assigned to # # the else section - in this example it echos ERROR to the terminal window. # ############################################################################## variable=$(kdialog --separate-output --checklist "CHOOSE:" 1 "RED" on 2 "BLUE" off 3 "GREEN" off;); if [ "$?" = 0 ]; then echo "$variable"; elif [ "$?" = 1 ]; then echo "YOU CHOSE CANCEL"; else echo "ERROR"; fi;
- Example 5:
-
#!/bin/bash ############################################################################## # This script opens a Kdialog window with a two-line message (created by # # using an HTML <br> tag) that offers you a combo box from which to # # make a choice. When you make the choice, command substitution is used to # # save your choice to a variable that is used to determine which of the six # # possible messages to display in the terminal window based on which choice # # you make or whether you make one all. # # # # The combo box returns 0 if the Enter key or the OK button is pressed. In # # that case, the script executes the action you assigned to 0 - in this # # example it echos the number or numbers you chose to the terminal window, # # each surrounded in "quotes" with a space between them. # # # # The combo box returns 1 if the Esc key or Cancel button is pressed. In # # that case, the combo box bypasses the choices in the combo box and chooses # # to take the action in the else section - in this example it echos YOU # # CHOSE CANCEL to the terminal window. # # # # If anything else happens, the script executes the action you assigned to # # the else section - in this example it echos ERROR to the terminal window. # ############################################################################## variable=$(kdialog --separate-output --checklist "LINE1<br>LINE2" 1 "RED" on 2 "BLUE" off 3 "GREEN" off;); if [ "$?" = 0 ]; then echo "$variable"; elif [ "$?" = 1 ]; then echo "YOU CHOSE CANCEL"; else echo "ERROR"; fi;
Combo box
- Example 1:
-
#!/bin/bash ############################################################################## # This script opens a Kdialog window with a single-line message that offers # # you a combo box from which to make a choice. When you make the choice, # # command substitution is used to save your choice to a variable that is # # used to determine which of the six possible messages to display in the # # terminal window based on which choice you make or whether you make one at # # all. # # # # The combo box returns 0 if the Enter key or the OK button is pressed. In # # that case, the script executes the action you assigned to 0 - in this # # example it echos a color or a reminder to you to choose a color to the # # terminal window. # # # # The combo box returns 1 if the Esc key or Cancel button is pressed. In # # that case, the combo box bypasses the choices in the combo box and chooses # # to take the action in the else section - in this example it echos YOU # # CHOSE CANCEL to the terminal window. # # # # If anything else happens, the script executes the action you assigned to # # the else section - in this example it echos ERROR to the terminal window. # ############################################################################## variable=`kdialog --combobox "CHOOSE:" "RED" "BLUE" "GREEN";`; if [ "$?" = 0 ]; then if [ "$variable" = RED ]; then echo "YOU CHOSE RED"; elif [ "$variable" = BLUE ]; then echo "YOU CHOSE BLUE"; elif [ "$variable" = GREEN ]; then echo "YOU CHOSE GREEN"; else echo "PLEASE CHOOSE A COLOR"; fi; elif [ "$?" = 1 ]; then echo "YOU CHOSE CANCEL"; else echo "ERROR"; fi;
- Example 2:
-
#!/bin/bash ############################################################################## # This script opens a Kdialog window with a single-line message that offers # # you a combo box from which to make a choice. When you make the choice, # # command substitution is used to save your choice to a variable that is # # used to determine which of the six possible messages to display in the # # terminal window based on which choice you make or whether you make one at # # all. # # # # The combo box returns 0 if the Enter key or the OK button is pressed. In # # that case, the script executes the action you assigned to 0 - in this # # example it echos a color or a reminder to you to choose a color to the # # terminal window. # # # # The combo box returns 1 if the Esc key or Cancel button is pressed. In # # that case, the combo box bypasses the choices in the combo box and chooses # # to take the action in the else section - in this example it echos YOU # # CHOSE CANCEL to the terminal window. # # # # If anything else happens, the script executes the action you assigned to # # the else section - in this example it echos ERROR to the terminal window. # ############################################################################## variable=$(kdialog --combobox "CHOOSE:" "RED" "BLUE" "GREEN";); if [ "$?" = 0 ]; then if [ "$variable" = RED ]; then echo "YOU CHOSE RED"; elif [ "$variable" = BLUE ]; then echo "YOU CHOSE BLUE"; elif [ "$variable" = GREEN ]; then echo "YOU CHOSE GREEN"; else echo "PLEASE CHOOSE A COLOR"; fi; elif [ "$?" = 1 ]; then echo "YOU CHOSE CANCEL"; else echo "ERROR"; fi;
- Example 3:
-
#!/bin/bash ############################################################################## # This script opens a Kdialog window with a two-line message (created by # # using an HTML <br> tag) that offers you a combo box from which to # # make a choice. When you make the choice, command substitution is used to # # save your choice to a variable that is used to determine which of the six # # possible messages to display in the terminal window based on which choice # # you make or whether you make one at all. # # # # The combo box returns 0 if the Enter key or the OK button is pressed. In # # that case, the script executes the action you assigned to 0 - in this # # example it echos a color or a reminder to you to choose a color to the # # terminal window. # # # # The combo box returns 1 if the Esc key or Cancel button is pressed. In # # that case, the combo box bypasses the choices in the combo box and chooses # # to take the action in the else section - in this example it echos YOU # # CHOSE CANCEL to the terminal window. # # # # If anything else happens, the script executes the action you assigned to # # the else section - in this example it echos ERROR to the terminal window. # ############################################################################## variable=$(kdialog --combobox "LINE1<br>LINE2" "RED" "BLUE" "GREEN"); if [ "$?" = 0 ]; then if [ "$variable" = RED ]; then echo "YOU CHOSE RED"; elif [ "$variable" = BLUE ]; then echo "YOU CHOSE BLUE"; elif [ "$variable" = GREEN ]; then echo "YOU CHOSE GREEN"; else echo "PLEASE CHOOSE A COLOR"; fi; elif [ "$?" = 1 ]; then echo "YOU CHOSE CANCEL"; else echo "ERROR"; fi;
Get existing directory
- Example 1:
-
#!/bin/bash ############################################################################## # This script opens a Kdialog window that lets you browse to a directory or # # create a new one. Command substitution is used to echo a specific message # # to the terminal window based on which directory you choose or create, if # # any or if somthing goes wrong. # # # # The command returns 0 if the New Folder... button is used to create a new # # folder and then the OK button or the Enter key is pressed, or if an # # existing folder is selected and the OK button or the Enter key is pressed. # # It then executes the command specified for a return of 0 - in this example # # it echos the path to the folder you created or selected to the terminal # # window. # # # # The command returns 1 if the Esc key or Cancel button is pressed. It then # # echos YOU CHOSE CANCEL to the terminal window, # # # # If anything else happens, the script executes the action you assigned to # # the else section - in this example it echos ERROR to the terminal window. # ############################################################################## variable=`kdialog --getexistingdirectory *;`; if [ "$?" = 0 ]; then echo "$variable"; elif [ "$?" = 1 ]; then echo "YOU CHOSE CANCEL"; else echo "ERROR"; fi;
- Example 2:
-
#!/bin/bash ############################################################################## # This script opens a Kdialog window that lets you browse to a directory or # # create a new one. Command substitution is used to echo a specific message # # to the terminal window based on which directory you choose or create, if # # any or if somthing goes wrong. # # # # The command returns 0 if the New Folder... button is used to create a new # # folder and then the OK button or the Enter key is pressed, or if an # # existing folder is selected and the OK button or the Enter key is pressed. # # It then executes the command specified for a return of 0 - in this exampl # # it echos the path to the folder you created or selected to the terminal # # window. # # # # The command returns 1 if the Esc key or Cancel button is pressed. It then # # echos YOU CHOSE CANCEL to the terminal window, # # # # If anything else happens, the script executes the action you assigned to # # the else section - in this example it echos ERROR to the terminal window. # ############################################################################## variable=$(kdialog --getexistingdirectory *;); if [ "$?" = 0 ]; then echo "$variable"; elif [ "$?" = 1 ]; then echo "YOU CHOSE CANCEL"; else echo "ERROR"; fi;
Get open file name
- Example 1:
-
#!/bin/bash ############################################################################### # This script opens a Kdialog file browsing window that expects you to choose # # a file to open starting in the current directory. Command substitution is # # used to save the path to the file you choose to a variable. The Kdialog # # command is tested to determine which action to take. # # # # The Kdialog command returns 0 if the Open button is pressed or if the Enter # # key is pressed when a file name has been selected or if a file name is # # double-clicked. In that case, the script executes the action you assigned # # to 0 - in this example it echos the variable that contains your selection # # to the terminal window. # # # # The Kdialog command returns 1 if the Esc key or Cancel button is pressed. # # In that case, the script takes the action in you assigned to 1 - in this # # example it echos YOU CHOSE CANCEL to the terminal window. # # # # If anything else happens, the script executes the action you assigned to # # the else section - in this example it echos ERROR to the terminal window. # ############################################################################### variable=`kdialog --getopenfilename .`; if [ "$?" = 0 ]; then echo "$variable"; elif [ "$?" = 1 ]; then echo "YOU CHOSE CANCEL"; else echo "ERROR"; fi;
- Example 2:
-
#!/bin/bash ############################################################################### # This script opens a Kdialog file browsing window that expects you to choose # # a file to open starting in the current directory. Command substitution is # # used to save the path to the file you choose to a variable. The Kdialog # # command is tested to determine which action to take. # # # # The Kdialog command returns 0 if the Open button is pressed or if the Enter # # key is pressed when a file name has been selected or if a file name is # # double-clicked. In that case, the script executes the action you assigned # # to 0 - in this example it echos the variable that contains your selection # # to the terminal window. # # # # The Kdialog command returns 1 if the Esc key or Cancel button is pressed. # # In that case, the script takes the action in you assigned to 1 - in this # # example it echos YOU CHOSE CANCEL to the terminal window. # # # # If anything else happens, the script executes the action you assigned to # # the else section - in this example it echos ERROR to the terminal window. # ############################################################################### variable=$(kdialog --getopenfilename .); if [ "$?" = 0 ]; then echo "$variable"; elif [ "$?" = 1 ]; then echo "YOU CHOSE CANCEL"; else echo "ERROR"; fi;
- Example 3:
-
#!/bin/bash ############################################################################### # This script opens a Kdialog file browsing window that expects you to choose # # a file to open starting in the specified directory (in this example it's # # the /PATH/ directory). Command substitution is used to save the path to the # # file you choose to a variable. The Kdialog command is tested to determine # # which action to take. # # # # The Kdialog command returns 0 if the Open button is pressed or if the Enter # # key is pressed when a file name has been selected or if a file name is # # double-clicked. In that case, the script executes the action you assigned # # to 0 - in this example it echos the variable that contains your selection # # to the terminal window. # # # # The Kdialog command returns 1 if the Esc key or Cancel button is pressed. # # In that case, the script takes the action in you assigned to 1 - in this # # example it echos YOU CHOSE CANCEL to the terminal window. # # # # If anything else happens, the script executes the action you assigned to # # the else section - in this example it echos ERROR to the terminal window. # ############################################################################### variable=$(kdialog --getopenfilename /PATH/.); if [ "$?" = 0 ]; then echo "$variable"; elif [ "$?" = 1 ]; then echo "YOU CHOSE CANCEL"; else echo "ERROR"; fi;
- Example 4:
-
#!/bin/bash ############################################################################### # This script opens a Kdialog file browsing window that expects you to choose # # a file with the specified extension (in this example the .txt and .html # # extensions are used) to open starting in the current directory. Command # # substitution is used to save the path to the file you choose to a variable. # # The Kdialog command is tested to determine which action to take. # # # # The Kdialog command returns 0 if the Open button is pressed or if the Enter # # key is pressed when a file name has been selected or if a file name is # # double-clicked. In that case, the script executes the action you assigned # # to 0 - in this example it echos the variable that contains your selection # # to the terminal window. # # # # The Kdialog command returns 1 if the Esc key or Cancel button is pressed. # # In that case, the script takes the action in you assigned to 1 - in this # # example it echos YOU CHOSE CANCEL to the terminal window. # # # # If anything else happens, the script executes the action you assigned to # # the else section - in this example it echos ERROR to the terminal window. # ############################################################################### variable=$(kdialog --getopenfilename . "*.txt *.html";); if [ "$?" = 0 ]; then echo "$variable"; elif [ "$?" = 1 ]; then echo "YOU CHOSE CANCEL"; else echo "ERROR"; fi;
- Example 5:
-
#!/bin/bash ############################################################################### # This script opens a Kdialog file browsing window that expects you to choose # # a file of the specified mime type (in this example the image/png, the # # txt/html, and the text/plain mime types are used) to open starting in the # # current directory. Command substitution is used to save the path to the # # file you choose to a variable. The Kdialog command is tested to determine # # which action to take. # # # # The Kdialog command returns 0 if the Open button is pressed or if the Enter # # key is pressed when a file name has been selected or if a file name is # # double-clicked. In that case, the script executes the action you assigned # # to 0 - in this example it echos the variable that contains your selection # # to the terminal window. # # # # The Kdialog command returns 1 if the Esc key or Cancel button is pressed. # # In that case, the script takes the action in you assigned to 1 - in this # # example it echos YOU CHOSE CANCEL to the terminal window. # # # # If anything else happens, the script executes the action you assigned to # # the else section - in this example it echos ERROR to the terminal window. # ############################################################################### variable=$(kdialog --getopenfilename . "image/png text/html text/plain";); if [ "$?" = 0 ]; then echo "$variable"; elif [ "$?" = 1 ]; then echo "YOU CHOSE CANCEL"; else echo "ERROR"; fi;
Get save file name
- Example 1:
-
#!/bin/bash ############################################################################### # This script opens a Kdialog file browsing window that expects you to choose # # a file starting in the current directory. Command substitution is used to # # save the path to the file you choose to a variable. The Kdialog command is # # tested to determine which action to take. # # # # The Kdialog command returns 0 if a file is selected and the Save button is # # pressed, or if a file name is double-clicked. In that case, the script # # executes the action you assigned to 0 - in this example it echos the # # variable that contains your selection to the terminal window. # # # # The Kdialog command returns 1 if the Esc key or Cancel button is pressed. # # In that case, the script takes the action in you assigned to 1 - in this # # example it echos YOU CHOSE CANCEL to the terminal window. # # # # If anything else happens, the script executes the action you assigned to # # the else section - in this example it echos ERROR to the terminal window. # ############################################################################### variable=`kdialog --getsavefilename .;`; if [ "$?" = 0 ]; then echo "$variable"; elif [ "$?" = 1 ]; then echo "YOU CHOSE CANCEL"; else echo "ERROR"; fi;
- Example 2:
-
#!/bin/bash ############################################################################### # This script opens a Kdialog file browsing window that expects you to choose # # a file starting in the current directory. Command substitution is used to # # save the path to the file you choose to a variable. The Kdialog command is # # tested to determine which action to take. # # # # The Kdialog command returns 0 if a file is selected and the Save button is # # pressed, or if a file name is double-clicked. In that case, the script # # executes the action you assigned to 0 - in this example it echos the # # variable that contains your selection to the terminal window. # # # # The Kdialog command returns 1 if the Esc key or Cancel button is pressed. # # In that case, the script takes the action in you assigned to 1 - in this # # example it echos YOU CHOSE CANCEL to the terminal window. # # # # If anything else happens, the script executes the action you assigned to # # the else section - in this example it echos ERROR to the terminal window. # ############################################################################### variable=$(kdialog --getsavefilename .;); if [ "$?" = 0 ]; then echo "$variable"; elif [ "$?" = 1 ]; then echo "YOU CHOSE CANCEL"; else echo "ERROR"; fi;
- Example 3:
-
#!/bin/bash ############################################################################### # This script opens a Kdialog file browsing window that expects you to choose # # a file starting in the directory specified by the PATH in the command. # # Command substitution is used to save the path to the file you choose to a # # variable. The Kdialog command is tested to determine which action to take. # # # # The Kdialog command returns 0 if a file is selected and the Save button is # # pressed, or if a file name is double-clicked. In that case, the script # # executes the action you assigned to 0 - in this example it echos the # # variable that contains your selection to the terminal window. # # # # The Kdialog command returns 1 if the Esc key or Cancel button is pressed. # # In that case, the script takes the action in you assigned to 1 - in this # # example it echos YOU CHOSE CANCEL to the terminal window. # # # # If anything else happens, the script executes the action you assigned to # # the else section - in this example it echos ERROR to the terminal window. # ############################################################################### variable=$(kdialog --getsavefilename /PATH/.;); if [ "$?" = 0 ]; then echo "$variable"; elif [ "$?" = 1 ]; then echo "YOU CHOSE CANCEL"; else echo "ERROR"; fi;
- Example 4:
-
#!/bin/bash ############################################################################### # This script opens a Kdialog file browsing window that expects you to choose # # a file of the specified type (in this example files with the .txt extension # # are acceptable) starting in the current directory. Command substitution is # # used to save the path to the file you choose to a variable. The Kdialog # # command is tested to determine which action to take. # # # # The Kdialog command returns 0 if a file is selected and the Save button is # # pressed, or if a file name is double-clicked. In that case, the script # # executes the action you assigned to 0 - in this example it echos the # # variable that contains your selection to the terminal window. # # # # The Kdialog command returns 1 if the Esc key or Cancel button is pressed. # # In that case, the script takes the action in you assigned to 1 - in this # # example it echos YOU CHOSE CANCEL to the terminal window. # # # # If anything else happens, the script executes the action you assigned to # # the else section - in this example it echos ERROR to the terminal window. # ############################################################################### variable=$(kdialog --getsavefilename . "*.txt";); if [ "$?" = 0 ]; then echo "$variable"; elif [ "$?" = 1 ]; then echo "YOU CHOSE CANCEL"; else echo "ERROR"; fi;
Input box
- Example 1:
-
#!/bin/bash ############################################################################### # This script opens a Kdialog window with a single-line message that asks you # # to type in some input. Command substitution is used to save your input to a # # variable. The script then tests the Kdialog command's return to determine # # which action to take based on the input you entered or whether you entered # # any at all. # # # # The Kdialog command returns 0 if the Enter key or the OK button is pressed. # # In that case, the script executes the action you assigned to 0 - in this # # example it echos your input to the terminal window. # # # # The Kdialog command returns 1 if the Esc key or Cancel button is pressed. # # In that case, the script takes the action in you assigned to 1 - in this # # example it echos YOU CHOSE CANCEL to the terminal window. # # # # If anything else happens, the script executes the action you assigned to # # the else section - in this example it echos ERROR to the terminal window. # ############################################################################### variable=`kdialog --inputbox "MESSAGE";`; if [ "$?" = 0 ]; then echo "$variable"; elif [ "$?" = 1 ]; then echo "YOU CHOSE CANCEL"; else echo "ERROR"; fi;
- Example 2:
-
#!/bin/bash ############################################################################### # This script opens a Kdialog window with a single-line message that asks you # # to type in some input. Command substitution is used to save your input to a # # variable. The script then tests the Kdialog command's return to determine # # which action to take based on the input you entered or whether you entered # # any at all. # # # # The Kdialog command returns 0 if the Enter key or the OK button is pressed. # # In that case, the script executes the action you assigned to 0 - in this # # example it echos your input to the terminal window. # # # # The Kdialog command returns 1 if the Esc key or Cancel button is pressed. # # In that case, the script takes the action in you assigned to 1 - in this # # example it echos YOU CHOSE CANCEL to the terminal window. # # # # If anything else happens, the script executes the action you assigned to # # the else section - in this example it echos ERROR to the terminal window. # ############################################################################### variable=$(kdialog --inputbox "MESSAGE";); if [ "$?" = 0 ]; then echo "$variable"; elif [ "$?" = 1 ]; then echo "YOU CHOSE CANCEL"; else echo "ERROR"; fi;
- Example 3:
-
#!/bin/bash ############################################################################### # This script opens a Kdialog window with a two-line message (created by # # using an HTML <br> tag) that asks you to type in some input. Command # # substitution is used to save your input to a variable. The script then # # tests the Kdialog command's return to determine which action to take based # # on the input you entered or whether you entered any at all. # # # # The Kdialog command returns 0 if the Enter key or the OK button is pressed. # # In that case, the script executes the action you assigned to 0 - in this # # example it echos your input to the terminal window. # # # # The Kdialog command returns 1 if the Esc key or Cancel button is pressed. # # In that case, the script takes the action in you assigned to 1 - in this # # example it echos YOU CHOSE CANCEL to the terminal window. # # # # If anything else happens, the script executes the action you assigned to # # the else section - in this example it echos ERROR to the terminal window. # ############################################################################### variable=$(kdialog --inputbox "LINE1<br>LINE2";); if [ "$?" = 0 ]; then echo "$variable"; elif [ "$?" = 1 ]; then echo "YOU CHOSE CANCEL"; else echo "ERROR"; fi;
- Example 4:
-
#!/bin/bash ############################################################################### # This script opens a Kdialog window (with the EXAMPLE title) with a # # single-line message that asks you to type in some input. Command # # substitution is used to save your input to a variable. The script then # # tests the Kdialog command's return to determine which action to take based # # on the input you entered or whether you entered any at all. # # # # The Kdialog command returns 0 if the Enter key or the OK button is pressed. # # In that case, the script executes the action you assigned to 0 - in this # # example it echos your input to the terminal window. # # # # The Kdialog command returns 1 if the Esc key or Cancel button is pressed. # # In that case, the script takes the action in you assigned to 1 - in this # # example it echos YOU CHOSE CANCEL to the terminal window. # # # # If anything else happens, the script executes the action you assigned to # # the else section - in this example it echos ERROR to the terminal window. # ############################################################################### variable=$(kdialog --inputbox "MESSAGE" --title "EXAMPLE";); if [ "$?" = 0 ]; then echo "$variable"; elif [ "$?" = 1 ]; then echo "YOU CHOSE CANCEL"; else echo "ERROR"; fi;
- Example 5:
-
#!/bin/bash ############################################################################### # This script opens a Kdialog window with a single-line message that asks you # # to type in some input. Command substitution is used to save your input to a # # variable. The script then tests the Kdialog command's return to determine # # which action to take based on the input you entered or whether you entered # # any at all. # # # # The Kdialog command returns 0 if the Enter key or the OK button is pressed. # # In that case, the script executes the action you assigned to 0 - in this # # example it echos your input to the file named FILENAME in the current # # directory, creating it if it doesn't exist and overwriting it if it does. # # # # The Kdialog command returns 1 if the Esc key or Cancel button is pressed. # # In that case, the script takes the action in you assigned to 1 - in this # # example it echos YOU CHOSE CANCEL to the terminal window. # # # # If anything else happens, the script executes the action you assigned to # # the else section - in this example it echos ERROR to the terminal window. # ############################################################################### variable=$(kdialog --inputbox "MESSAGE";); if [ "$?" = 0 ]; then echo "$variable" > FILENAME; elif [ "$?" = 1 ]; then echo "YOU CHOSE CANCEL"; else echo "ERROR"; fi;
- Example 6:
-
#!/bin/bash ############################################################################### # This script opens a Kdialog window with a single-line message that asks you # # to type in some input. Example input is provided in the input box. Command # # substitution is used to save your input to a variable. The script then # # tests the Kdialog command's return to determine which action to take based # # on the input you entered or whether you entered any at all. # # # # The Kdialog command returns 0 if the Enter key or the OK button is pressed. # # In that case, the script executes the action you assigned to 0 - in this # # example it echos your input to the terminal window unless you don't provide # # any, in which case it echos DEFAULT to the terminal window, # # # # The Kdialog command returns 1 if the Esc key or Cancel button is pressed. # # In that case, the script takes the action in you assigned to 1 - in this # # example it echos YOU CHOSE CANCEL to the terminal window. # # # # If anything else happens, the script executes the action you assigned to # # the else section - in this example it echos ERROR to the terminal window. # ############################################################################### variable=$(kdialog --inputbox "MESSAGE" "DEFAULT";); if [ "$?" = 0 ]; then echo "$variable"; elif [ "$?" = 1 ]; then echo "YOU CHOSE CANCEL"; else echo "ERROR"; fi;
Menu
- Example 1:
-
#!/bin/bash ############################################################################## # This script opens a Kdialog window with a single-line message that offers # # you a menu of choices. When you make a choice, command substitution is # # used to save your choice to a variable that is used to determine which of # # the five possible messages to display in the terminal window based on # # which choice you make or whether you make one at all. # # # # The menu returns 0 if the Enter key or the OK button is pressed. In that # # case, the script uses the choices you gave it, or the fact that you didn't # # make a choice, to determine which action to take - in this example, it # # echos a message to the terminal window. # # # # The menu returns 1 if the Esc key or Cancel button is pressed. In that # # case, the menu bypasses the choices and takes the action in the else # # section - in this example it echos YOU CHOSE CANCEL to the terminal # # window. # ############################################################################## variable=`kdialog --menu "CHOOSE:" A "APPLES" B "BANANAS" C "COCONUTS";`; if [ "$?" = 0 ]; then if [ "$variable" = A ]; then echo "YOU CHOSE A"; elif [ "$variable" = B ]; then echo "YOU CHOSE B"; elif [ "$variable" = C ]; then echo "YOU CHOSE C"; else echo "ERROR"; fi; else echo "YOU CHOSE CANCEL"; fi;
- Example 2:
-
#!/bin/bash ############################################################################## # This script opens a Kdialog window with a single-line message that offers # # you a menu of choices. When you make a choice, command substitution is # # used to save your choice to a variable that is used to determine which of # # the five possible messages to display in the terminal window based on # # which choice you make or whether you make one at all. # # # # The menu returns 0 if the Enter key or the OK button is pressed. In that # # case, the script uses the choices you gave it, or the fact that you didn't # # make a choice, to determine which action to take - in this example, it # # echos a message to the terminal window. # # # # The menu returns 1 if the Esc key or Cancel button is pressed. In that # # case, the menu bypasses the choices and takes the action in the else # # section - in this example it echos YOU CHOSE CANCEL to the terminal # # window. # ############################################################################## variable=$(kdialog --menu "CHOOSE:" A "APPLES" B "BANANAS" C "COCONUTS";); if [ "$?" = 0 ]; then if [ "$variable" = A ]; then echo "YOU CHOSE A"; elif [ "$variable" = B ]; then echo "YOU CHOSE B"; elif [ "$variable" = C ]; then echo "YOU CHOSE C"; else echo "ERROR"; fi; else echo "YOU CHOSE CANCEL"; fi;
- Example 3:
-
#!/bin/bash ############################################################################## # This script opens a Kdialog window with a two-line message (created by # # using an HTML <br> tag) that offers you a menu of choices. When you # # make a choice, command substitution is used to save your choice to a # # variable that is used to determine which of the five possible messages to # # display in the terminal window based on which choice you make or whether # # you make one at all. # # # # The menu returns 0 if the Enter key or the OK button is pressed. In that # # case, the script uses the choices you gave it, or the fact that you didn't # # make a choice, to determine which action to take - in this example, it # # echos a message to the terminal window. # # # # The menu returns 1 if the Esc key or Cancel button is pressed. In that # # case, the menu bypasses the choices and takes the action in the else # # section - in this example it echos YOU CHOSE CANCEL to the terminal # # window. # ############################################################################## variable=$(kdialog --menu "LINE1<BR>LINE2:" A "APPLES" B "BANANAS" C "COCONUTS";); if [ "$?" = 0 ]; then if [ "$variable" = A ]; then echo "YOU CHOSE A"; elif [ "$variable" = B ]; then echo "YOU CHOSE B"; elif [ "$variable" = C ]; then echo "YOU CHOSE C"; else echo "ERROR"; fi; else echo "YOU CHOSE CANCEL"; fi;
Menu – alternate method
A APPLES B BANANAS C COCONUTS
Then you can use any of the examples below to work with the text file. If the text file isn’t in the same directory as the script, provide the full path to the file instead of just the file name.
- Example 1:
-
#!/bin/bash ############################################################################## # This script opens a Kdialog window with a single-line message that offers # # you a menu of choices that are gotten by using command substitution to # # read the contents of a file (in this case I used FILENAME), and by using # # command substitution to determine what you choose, if anything, and # # whether there is some sort of error. The result is saved to a variable # # that is tested to determine which action to take - in this example it will # # echo text to the terminal window. # # # # The menu returns 0 if the Enter key or the OK button is pressed. In that # # case, the script uses the choices you gave it, or the fact that you didn't # # make a choice, to determine which action to take - in this example, it # # echos text to the terminal window. # # # # The menu returns 1 if the Esc key or Cancel button is pressed. In that # # case, the menu bypasses the choices and takes the action in the else # # section - in this example it echos YOU CHOSE CANCEL to the terminal # # window. # ############################################################################## variable=`kdialog --menu "CHOOSE:" $(cat FILENAME;);`; if [ "$?" = 0 ]; then if [ "$variable" = A ]; then echo "YOU CHOSE A"; elif [ "$variable" = B ]; then echo "YOU CHOSE B"; elif [ "$variable" = C ]; then echo "YOU CHOSE C"; elif [ "$?" = 2 ]; then echo "YOU CHOSE CANCEL"; else echo "ERROR"; fi; else echo "YOU CHOSE CANCEL"; fi;
- Example 2:
-
#!/bin/bash ############################################################################## # This script opens a Kdialog window with a single-line message that offers # # you a menu of choices that are gotten by using command substitution to # # read the contents of a file (in this example I used FILENAME). # # # # Command substitution is then used to determine what you choose, if # # anything, and whether there is some sort of error. The result is saved to # # a variable that is tested to determine which action to take - in this # # example it will echo text to the terminal window. # # # # The menu returns 0 if the Enter key or the OK button is pressed. In that # # case, the script uses the choices you gave it, or the fact that you didn't # # make a choice, to determine which action to take - in this example, it # # echos text to the terminal window. # # # # The menu returns 1 if the Esc key or Cancel button is pressed. In that # # case, the menu bypasses the choices and takes the action in the else # # section - in this example it echos YOU CHOSE CANCEL to the terminal # # window. # ############################################################################## variable=$(kdialog --menu "CHOOSE:" $(cat FILENAME;);); if [ "$?" = 0 ]; then if [ "$variable" = A ]; then echo "YOU CHOSE A"; elif [ "$variable" = B ]; then echo "YOU CHOSE B"; elif [ "$variable" = C ]; then echo "YOU CHOSE C"; elif [ "$?" = 2 ]; then echo "YOU CHOSE CANCEL"; else echo "ERROR"; fi; else echo "YOU CHOSE CANCEL"; fi;
- Example 3:
-
#!/bin/bash ############################################################################## # This script opens a Kdialog window with a single-line message that offers # # you a menu of choices. Command substitution is used to read the contents # # of a file (in this case I used FILENAME) and save them to a variable. # # Command substitution is also used to determine what you choose, if # # anything, and whether there is some sort of error. The result is saved to # # a variable that is tested to determine which action to take - in this # # example it will echo text to the terminal window. # # # # The menu returns 0 if the Enter key or the OK button is pressed. In that # # case, the script uses the choices you gave it, or the fact that you didn't # # make a choice, to determine which action to take - in this example, it # # echos text to the terminal window. # # # # The menu returns 1 if the Esc key or Cancel button is pressed. In that # # case the menu bypasses the choices and takes the action in the else # # section - in this example it echos YOU CHOSE CANCEL to the terminal # # window. # ############################################################################## contents=`cat FILENAME;`; variable=`kdialog --menu "CHOOSE:" $contents;`; if [ "$?" = 0 ]; then if [ "$variable" = A ]; then echo "YOU CHOSE A"; elif [ "$variable" = B ]; then echo "YOU CHOSE B"; elif [ "$variable" = C ]; then echo "YOU CHOSE C"; else echo "ERROR"; fi; else echo "YOU CHOSE CANCEL"; fi;
- Example 4:
-
#!/bin/bash ############################################################################## # This script opens a Kdialog window with a single-line message that offers # # you a menu of choices. Command substitution is used to read the contents # # of a file (in this case I used FILENAME) and save them to a variable. # # Command substitution is also used to determine what you choose, if # # anything, and whether there is some sort of error. The result is saved to # # a variable that is tested to determine which action to take - in this # # example it will echo text to the terminal window. # # # # The menu returns 0 if the Enter key or the OK button is pressed. In that # # case, the script uses the choices you gave it, or the fact that you didn't # # make a choice, to determine which action to take - in this cas it echos # # text to the terminal window). # # # # The menu returns 1 if the Esc key or Cancel button is pressed. The menu # # then bypasses the choices and takes the action in the else section - in # # this case it echos YOU CHOSE CANCEL to the terminal window. # ############################################################################## contents=$(cat FILENAME;); variable=$(kdialog --menu "CHOOSE:" $contents;); if [ "$?" = 0 ]; then if [ "$variable" = A ]; then echo "YOU CHOSE A"; elif [ "$variable" = B ]; then echo "YOU CHOSE B"; elif [ "$variable" = C ]; then echo "YOU CHOSE C"; else echo "ERROR"; fi; else echo "YOU CHOSE CANCEL"; fi;
Message box – error
- Example 1:
-
#!/bin/bash ############################################################################### # This script opens a Kdialog window that displays your error message. The # # command always returns 0. # ############################################################################### kdialog --error "MESSAGE";
- Example 2:
-
#!/bin/bash ############################################################################### # This script opens a Kdialog window with the EXAMPLE title. The window # # displays your error message. The command always returns 0. # ############################################################################### kdialog --error "MESSAGE" --title "EXAMPLE";
- Example 3:
-
#!/bin/bash ############################################################################### # This script opens a Kdialog window that displays your error message. The # # HTML <br> tag is used to add a carriage return. The command always # # returns 0. # ############################################################################### kdialog --error "LINE1<br>LINE2";
Message box – information
- Example 1:
-
#!/bin/bash ############################################################################### # This script opens a Kdialog window that displays your information message. # # The command always returns 0. # ############################################################################### kdialog --msgbox "MESSAGE";
- Example 2:
-
#!/bin/bash ############################################################################### # This script opens a Kdialog window that displays your information message. # # The HTML <br> tag is used to add a carriage return. The command # # always returns 0. # ############################################################################### kdialog --msgbox "LINE1<br>LINE2";
- Example 3:
-
#!/bin/bash ############################################################################### # This script opens a Kdialog window with the EXAMPLE title. The window # # displays your information message. The command always returns 0. # ############################################################################### kdialog --title "EXAMPLE" --msgbox "MESSAGE";
- Example 4:
-
#!/bin/bash ############################################################################### # This script opens a Kdialog window that is attached to the current window. # # The Kdialog window displays your information message. The command always # # returns 0. # ############################################################################### kdialog ${WINDOWID:+--attach $WINDOWID} --msgbox "MESSAGE";
Message box – sorry
- Example 1:
-
#!/bin/bash ############################################################################### # This script opens a Kdialog window that displays your message. The command # # always returns 0. # ############################################################################### kdialog --sorry "MESSAGE";
- Example 2:
-
#!/bin/bash ############################################################################### # This script opens a Kdialog window that displays your message. The HTML # # <br> tag is used to add a carriage return. The command always # # returns 0. # ############################################################################### kdialog --sorry "LINE1<br>LINE2";
- Example 3:
-
#!/bin/bash ############################################################################### # This script opens a Kdialog window with the EXAMPLE title. The window # # displays your message. The command always returns 0. # ############################################################################### kdialog --title "EXAMPLE" --sorry "MESSAGE";
Passive pop-up
- Example 1:
-
#!/bin/bash ############################################################################# # This script opens a Kdialog passive pop-up window that displays a # # single-line message for a specified number of seconds. The command always # # returns 0. # # # ############################################################################# kdialog --passivepopup "MESSAGE" 5;
- Example 2:
-
#!/bin/bash ############################################################################# # This script opens a Kdialog passive pop-up window that displays a # # two-line message (created by using an HTML <br> tag) for a # # specified number of seconds. The command always returns 0. # # # ############################################################################# kdialog --passivepopup "LINE1<br>LINE2" 5;
- Example 3:
-
#!/bin/bash ############################################################################# # This script opens a Kdialog passive pop-up window with the EXAMPLE title, # # The window displays a single-line message for a specified number of # # seconds. The command always returns 0. # # # ############################################################################# kdialog --title "EXAMPLE" --passivepopup "MESSAGE" 5;
Password
- Example 1:
-
#!/bin/bash ############################################################################### # This script opens a Kdialog password input window with a single-line # # message that asks you to enter your password. Command substitution is used # # to store your response, if any, in a variable that is tested to determine # # which action to take. # # # # The command returns nothing and inserts a blank line into the terminal # # window if nothing is entered into the box and the OK button or the Enter # # key is pressed. # # # # The command returns 0 if input is entered into the box and the OK button or # # the Enter key is pressed. It then executes the command specified for a # # return of 0 - in this example it echos the password to the terminal window. # # # # The command returns 1 if the Cancel button or the Enter key is pressed. It # # then executes the command specified for a return of 1 - in this example it # # echos YOU CHOSE CANCEL to the terminal window. # # # # If anything else happens, the script executes the action you assigned to # # the else section - in this example it echos ERROR to the terminal window. # ############################################################################### variable=`kdialog --password "Please enter your password:";`; if [ "$?" = 0 ]; then echo "$variable"; elif [ "$?" = 1 ]; then echo "YOU CHOSE CANCEL"; else echo "ERROR"; fi;
- Example 2:
-
#!/bin/bash ############################################################################### # This script opens a Kdialog password input window with a single-line # # message that asks you to enter your password. Command substitution is used # # to store your response, if any, in a variable that is tested to determine # # which action to take. # # # # The command returns nothing and inserts a blank line into the terminal # # window if nothing is entered into the box and the OK button or the Enter # # key is pressed. # # # # The command returns 0 if input is entered into the box and the OK button or # # the Enter key is pressed. It then executes the command specified for a # # return of 0 - in this example it echos the password to the terminal window. # # # # The command returns 1 if the Cancel button or the Enter key is pressed. It # # then executes the command specified for a return of 1 - in this example it # # echos YOU CHOSE CANCEL to the terminal window. # # # # If anything else happens, the script executes the action you assigned to # # the else section - in this example it echos ERROR to the terminal window. # ############################################################################### variable=$(kdialog --password "Please enter your password:";); if [ "$?" = 0 ]; then echo "$variable"; elif [ "$?" = 1 ]; then echo "YOU CHOSE CANCEL"; else echo "ERROR"; fi;
- Example 3:
-
#!/bin/bash ############################################################################### # This script opens a Kdialog password input window with a two-line message # # (created by using an HTML <br> tag) that asks you to enter your # # password. Command substitution is used to store your response, if any, in a # # variable that is tested to determine which action to take. # # # # The command returns nothing and inserts a blank line into the terminal # # window if nothing is entered into the box and the OK button or the Enter # # key is pressed. # # # # The command returns 0 if input is entered into the box and the OK button or # # the Enter key is pressed. It then executes the command specified for a # # return of 0 - in this example it echos the password to the terminal window. # # # # The command returns 1 if the Cancel button or the Enter key is pressed. It # # then executes the command specified for a return of 1 - in this example it # # echos YOU CHOSE CANCEL to the terminal window. # # # # If anything else happens, the script executes the action you assigned to # # the else section - in this example it echos ERROR to the terminal window. # ############################################################################### variable=$(kdialog --password "LINE1<br>LINE2";); if [ "$?" = 0 ]; then echo "$variable"; elif [ "$?" = 1 ]; then echo "YOU CHOSE CANCEL"; else echo "ERROR"; fi;
Radio list
- Example 1:
-
#!/bin/bash ############################################################################# # This script opens a Kdialog window that displays a single-line message # # that asks you to choose an item from a radio list. Command substitution # # is used to store the result of the choice you make in a variable that is # # tested to determine which action the script will take. # # # # The Kdialog command returns 0 if the OK button or Enter key is pressed. # # The Kdialog command combined with the echo command following it returns # # 1, 2, or 3, depending on which item you highlighted when you pressed the # # OK button or the Enter key. In that case, the script takes the action you # # assigned to 1, 2, or 3 - in this example it echos YOU CHOSE RED, or it # # echos YOU CHOSE BLUE or it echos YOU CHOSE GREEN to the terminal window. # # If anything else happens, the script takes the action you assigned to # # else - in this example it echos ERROR to the terminal window. # # # # The Kdialog command returns 1 if the CANCEL button is pressed or if it is # # highlighted while the Enter key is pressed. In that case, the script # # takes the action you assigned to 1 - in this example it echos YOU CHOSE # # CANCEL to the terminal window. # # # # If anything else happens, the script takes the action you assigned to # # else - in this example it echos ERROR to the terminal window. # ############################################################################# variable=`kdialog --radiolist "CHOOSE:" 1 "RED" on 2 "BLUE" on 3 "GREEN" off;`; if [ "$?" = 0 ]; then if [ "$variable" = 1 ]; then echo "YOU CHOSE RED"; elif [ "$variable" = 2 ]; then echo "YOU CHOSE BLUE"; elif [ "$variable" = 3 ]; then echo "YOU CHOSE GREEN"; else echo "ERROR"; fi; elif [ "$?" = 1 ]; then echo "YOU CHOSE CANCEL"; else echo "ERROR"; fi;
- Example 2:
-
#!/bin/bash ############################################################################# # This script opens a Kdialog window that displays a single-line message # # that asks you to choose an item from a radio list. Command substitution # # is used to store the result of the choice you make in a variable that is # # tested to determine which action the script will take. # # # # The Kdialog command returns 0 if the OK button or Enter key is pressed. # # The Kdialog command combined with the echo command following it returns # # 1, 2, or 3, depending on which item you highlighted when you pressed the # # OK button or the Enter key. In that case, the script takes the action you # # assigned to 1, 2, or 3 - in this example it echos YOU CHOSE RED, or it # # echos YOU CHOSE BLUE or it echos YOU CHOSE GREEN to the terminal window. # # If anything else happens, the script takes the action you assigned to # # else - in this example it echos ERROR to the terminal window. # # # # The Kdialog command returns 1 if the CANCEL button is pressed or if it is # # highlighted while the Enter key is pressed. In that case, the script # # takes the action you assigned to 1 - in this example it echos YOU CHOSE # # CANCEL to the terminal window. # # # # If anything else happens, the script takes the action you assigned to # # else - in this example it echos ERROR to the terminal window. # ############################################################################# variable=$(kdialog --radiolist "CHOOSE:" 1 "RED" on 2 "BLUE" on 3 "GREEN" off;); if [ "$?" = 0 ]; then if [ "$variable" = 1 ]; then echo "YOU CHOSE RED"; elif [ "$variable" = 2 ]; then echo "YOU CHOSE BLUE"; elif [ "$variable" = 3 ]; then echo "YOU CHOSE GREEN"; else echo "ERROR"; fi; elif [ "$?" = 1 ]; then echo "YOU CHOSE CANCEL"; else echo "ERROR"; fi;
- Example 3:
-
#!/bin/bash ############################################################################# # This script opens a Kdialog window that displays a two-line message # # (created by using an HTML <br> tag) that asks you to choose an item # # from a radio list. Command substitution is used to store the result of # # the choice you make in a variable that is tested to determine which # # action the script will take. # # # # The Kdialog command returns 0 if the OK button or Enter key is pressed. # # The Kdialog command combined with the echo command following it returns # # 1, 2, or 3, depending on which item you highlighted when you pressed the # # OK button or the Enter key. In that case, the script takes the action you # # assigned to 1, 2, or 3 - in this example it echos YOU CHOSE RED, or it # # echos YOU CHOSE BLUE or it echos YOU CHOSE GREEN to the terminal window. # # If anything else happens, the script takes the action you assigned to # # else - in this example it echos ERROR to the terminal window. # # # # The Kdialog command returns 1 if the CANCEL button is pressed or if it is # # highlighted while the Enter key is pressed. In that case, the script # # takes the action you assigned to 1 - in this example it echos YOU CHOSE # # CANCEL to the terminal window. # # # # If anything else happens, the script takes the action you assigned to # # else - in this example it echos ERROR to the terminal window. # ############################################################################# variable=$(kdialog --radiolist "LINE1<br>LINE2" 1 "RED" on 2 "BLUE" on 3 "GREEN" off;); if [ "$?" = 0 ]; then if [ "$variable" = 1 ]; then echo "YOU CHOSE RED"; elif [ "$variable" = 2 ]; then echo "YOU CHOSE BLUE"; elif [ "$variable" = 3 ]; then echo "YOU CHOSE GREEN"; else echo "ERROR"; fi; elif [ "$?" = 1 ]; then echo "YOU CHOSE CANCEL"; else echo "ERROR"; fi;
Text box
- Example 1:
-
#!/bin/bash ############################################################################### # This script opens a Kdialog text box window that displays the contents of # # the specified file (in this example it displays the FILENAME file) and # # offers and OK button for you to press when finished viewing the file. # # # # The Kdialog command returns 0 if the Enter key or OK button is pressed. In # # that case, the script executes the action you assigned to 0 - in this # # example it does nothing. # # # # The Kdialog command returns 1 if the Esc key is pressed. In that case, the # # script takes the action in you assigned to 1 - in this example it echos YOU # # CLOSED THE WINDOW to the terminal window. # # # # If anything else happens, the script executes the action you assigned to # # the else section - in this example it echos ERROR to the terminal window. # ############################################################################### kdialog --textbox FILENAME; if [ "$?" = 0 ]; then :; elif [ "$?" = 1 ]; then echo "YOU CLOSED THE WINDOW"; else echo "ERROR"; fi;
- Example 2:
-
#!/bin/bash ############################################################################### # This script opens a Kdialog text box window of the size specified in pixels # # (in this example it's 400 x 300) that displays the contents of the # # specified file (in this example it displays the FILENAME file) and offers # # and OK button for you to press when finished viewing the file. # # # # The Kdialog command returns 0 if the Enter key or OK button is pressed. In # # that case, the script executes the action you assigned to 0 - in this # # example it does nothing. # # # # The Kdialog command returns 1 if the Esc key is pressed. In that case, the # # script takes the action in you assigned to 1 - in this example it echos YOU # # CLOSED THE WINDOW to the terminal window. # # # # If anything else happens, the script executes the action you assigned to # # the else section - in this example it echos ERROR to the terminal window. # ############################################################################### kdialog --textbox FILENAME 400 300; if [ "$?" = 0 ]; then :; elif [ "$?" = 1 ]; then echo "YOU CLOSED THE WINDOW"; else echo "ERROR"; fi;
- Example 3:
-
#!/bin/bash ############################################################################### # This script opens a Kdialog text box window (with the EXAMPLE title) that # # displays the contents of the specified file (in this example it displays # # the FILENAME file) and offers and OK button for you to press when finished # # viewing the file. # # # # The Kdialog command returns 0 if the Enter key or OK button is pressed. In # # that case, the script executes the action you assigned to 0 - in this # # example it does nothing. # # # # The Kdialog command returns 1 if the Esc key is pressed. In that case, the # # script takes the action in you assigned to 1 - in this example it echos YOU # # CLOSED THE WINDOW to the terminal window. # # # # If anything else happens, the script executes the action you assigned to # # the else section - in this example it echos ERROR to the terminal window. # ############################################################################### kdialog --textbox FILENAME --title "EXAMPLE"; if [ "$?" = 0 ]; then :; elif [ "$?" = 1 ]; then echo "YOU CLOSED THE WINDOW"; else echo "ERROR"; fi;
Warning continue or cancel
- Example 1:
-
#!/bin/bash ############################################################################# # This script opens a Kdialog window that displays a single-line warning # # message that asks you to choose yes, no, or cancel. Command substitution # # is used to store the result of the choice you make, if any, in a variable # # that is tested to determine which action the script will take. # # # # The Kdialog command returns 0 if the Continue button or the Enter key is # # pressed. In that case, the script takes the action you assigned to 0 - in # # this example it echos YOU CHOSE CONTINUE to the terminal window. # # # # The Kdialog command returns 2 if the CANCEL button is pressed or if it is # # highlighted while the Enter key is pressed. In that case, the script # # takes the action you assigned to 1 - in this example it echos YOU CHOSE # # CANCEL to the terminal window. # # # # If anything else happens, the script takes the action you assigned to # # else - in this example it echos ERROR to the terminal window. # ############################################################################# variable=`kdialog --warningcontinuecancel "MESSAGE";echo "$?";`; if [ "$variable" = 0 ]; then echo "YOU CHOSE CONTINUE"; elif [ "$variable" = 2 ]; then echo "YOU CHOSE CANCEL"; else echo "ERROR"; fi;
- Example 2:
-
#!/bin/bash ############################################################################# # This script opens a Kdialog window that displays a single-line warning # # message that asks you to choose yes, no, or cancel. Command substitution # # is used to store the result of the choice you make, if any, in a variable # # that is tested to determine which action the script will take. # # # # The Kdialog command returns 0 if the Continue button or the Enter key is # # pressed. In that case, the script takes the action you assigned to 0 - in # # this example it echos YOU CHOSE CONTINUE to the terminal window. # # # # The Kdialog command returns 2 if the CANCEL button is pressed or if it is # # highlighted while the Enter key is pressed. In that case, the script # # takes the action you assigned to 1 - in this example it echos YOU CHOSE # # CANCEL to the terminal window. # # # # If anything else happens, the script takes the action you assigned to # # else - in this example it echos ERROR to the terminal window. # ############################################################################# variable=$(kdialog --warningcontinuecancel "MESSAGE";echo "$?";); if [ "$variable" = 0 ]; then echo "YOU CHOSE CONTINUE"; elif [ "$variable" = 2 ]; then echo "YOU CHOSE CANCEL"; else echo "ERROR"; fi;
- Example 3:
-
#!/bin/bash ############################################################################# # This script opens a Kdialog window that displays a two-line warning # # message (created by using an HTML <br> tag) that asks you to choose # # yes, no, or cancel. Command substitution is used to store the result of # # the choice you make, if any, in a variable that is tested to determine # # which action the script will take. # # # # The Kdialog command returns 0 if the Continue button or the Enter key is # # pressed. In that case, the script takes the action you assigned to 0 - in # # this example it echos YOU CHOSE CONTINUE to the terminal window. # # # # The Kdialog command returns 2 if the CANCEL button is pressed or if it is # # highlighted while the Enter key is pressed. In that case, the script # # takes the action you assigned to 1 - in this example it echos YOU CHOSE # # CANCEL to the terminal window. # # # # If anything else happens, the script takes the action you assigned to # # else - in this example it echos ERROR to the terminal window. # ############################################################################# variable=$(kdialog --warningcontinuecancel "LINE1<br>LINE2";echo "$?";); if [ "$variable" = 0 ]; then echo "YOU CHOSE CONTINUE"; elif [ "$variable" = 2 ]; then echo "YOU CHOSE CANCEL"; else echo "ERROR"; fi;
Warning yes or no
- Example 1:
-
#!/bin/bash ############################################################################### # This script opens a Kdialog warning yes no window with a single-line # # warning message that asks you to choose the Yes or No button. Your response # # is used to determine which action to take. # # # # The command returns 0 if the Yes button is pressed or if the Yes button is # # selected and the Enter key is pressed. The script then executes the command # # you specified for a return of 0 - in this example it echos YOU CHOSE YES to # # the terminal window. # # # # The command returns 1 if the Enter key is pressed without making a # # selection, if the No button is pressed, or if the No button is selected and # # the Enter key is pressed. It then executes the command you specified for a # # return of 1 - in this example it echos YOU CHOSE NO to the terminal window. # # # # If anything else happens, the script executes the action you assigned to # # the else section - in this example it echos ERROR to the terminal window. # ############################################################################### kdialog --warningyesno "CHOOSE:"; if [ "$?" = 0 ]; then echo "YOU CHOSE YES"; elif [ "$?" = 1 ]; then echo "YOU CHOSE NO"; else echo "ERROR"; fi;
- Example 2:
-
#!/bin/bash ############################################################################### # This script opens a Kdialog warning yes no window with a two-line warning # # message (created by using an HTML <br> tag) that asks you to choose # # the Yes or No button. Your response is used to determine which action to # # take. # # # # The command returns 0 if the Yes button is pressed or if the Yes button is # # selected and the Enter key is pressed. The script then executes the command # # you specified for a return of 0 - in this example it echos YOU CHOSE YES to # # the terminal window. # # # # The command returns 1 if the Enter key is pressed without making a # # selection, if the No button is pressed, or if the No button is selected and # # the Enter key is pressed. It then executes the command you specified for a # # return of 1 - in this example it echos YOU CHOSE NO to the terminal window. # # # # If anything else happens, the script executes the action you assigned to # # the else section - in this example it echos ERROR to the terminal window. # ############################################################################### kdialog --warningyesno "LINE1<br>LINE2"; if [ "$?" = 0 ]; then echo "YOU CHOSE YES"; elif [ "$?" = 1 ]; then echo "YOU CHOSE NO"; else echo "ERROR"; fi;
Warning yes or no or cancel
- Example 1:
-
#!/bin/bash ############################################################################### # This script opens a Kdialog warning yes no window with a single-line # # warning message that asks you to choose the Yes or No button. Your response # # is used to determine which action to take. Command substitution is used to # # save your choice to a variable that is used to determine which of the four # # messages to display in the terminal window based on which choice you make # # or whether you make one at all. # # # # The command returns 0 if the Enter key is pressed without making a # # selection, if th Yes button is pressed, or if the Yes button is selected # # and the Enter key is pressed. The script then executes the command you # # specified for a return of 0 - in this example it echos YOU CHOSE YES to the # # terminal window. # # # # The command returns 1 if the No button is pressed, or if the No button is # # selected and the Enter key is pressed. The script then executes the command # # you specified for a return of 1 - in this example it echos YOU CHOSE NO to # # the terminal window. # # # # The command returns 2 if the Cancel button or the Esc key is pressed. The # # script then executes the command you specified for a return of 2 - in this # # example it echos YOU CHOSE CANCEL to the terminal window. # # # # If anything else happens, the script executes the action you assigned to # # the else section - in this example it echos ERROR to the terminal window. # ############################################################################### variable=`kdialog --warningyesnocancel "MESSAGE";echo "$?";`; if [ "$variable" = 0 ]; then echo "YOU CHOSE YES"; elif [ "$variable" = 1 ]; then echo "YOU CHOSE NO"; elif [ "$variable" = 2 ]; then echo "YOU CHOSE CANCEL"; else echo "ERROR"; fi;
- Example 2:
-
#!/bin/bash ############################################################################### # This script opens a Kdialog warning yes no window with a single-line # # warning message that asks you to choose the Yes or No button. Your response # # is used to determine which action to take. Command substitution is used to # # save your choice to a variable that is used to determine which of the four # # messages to display in the terminal window based on which choice you make # # or whether you make one at all. # # # # The command returns 0 if the Enter key is pressed without making a # # selection, if th Yes button is pressed, or if the Yes button is selected # # and the Enter key is pressed. The script then executes the command you # # specified for a return of 0 - in this example it echos YOU CHOSE YES to the # # terminal window. # # # # The command returns 1 if the No button is pressed, or if the No button is # # selected and the Enter key is pressed. The script then executes the command # # you specified for a return of 1 - in this example it echos YOU CHOSE NO to # # the terminal window. # # # # The command returns 2 if the Cancel button or the Esc key is pressed. The # # script then executes the command you specified for a return of 2 - in this # # example it echos YOU CHOSE CANCEL to the terminal window. # # # # If anything else happens, the script executes the action you assigned to # # the else section - in this example it echos ERROR to the terminal window. # ############################################################################### variable=$(kdialog --warningyesnocancel "MESSAGE";echo "$?";); if [ "$variable" = 0 ]; then echo "YOU CHOSE YES"; elif [ "$variable" = 1 ]; then echo "YOU CHOSE NO"; elif [ "$variable" = 2 ]; then echo "YOU CHOSE CANCEL"; else echo "ERROR"; fi;
- Example 3:
-
#!/bin/bash ############################################################################### # This script opens a Kdialog warning yes no window with a two-line warning # # warning message (created by using an HTML <br> tag) that asks you to # # choose the Yes or No button. Your response is used to determine which # # action to take. Command substitution is used to save your choice to a # # variable that is used to determine which of the four messages to display in # # the terminal window based on which choice you make or whether you make one # # at all. # # # # The command returns 0 if the Enter key is pressed without making a # # selection, if th Yes button is pressed, or if the Yes button is selected # # and the Enter key is pressed. The script then executes the command you # # specified for a return of 0 - in this example it echos YOU CHOSE YES to the # # terminal window. # # # # The command returns 1 if the No button is pressed, or if the No button is # # selected and the Enter key is pressed. The script then executes the command # # you specified for a return of 1 - in this example it echos YOU CHOSE NO to # # the terminal window. # # # # The command returns 2 if the Cancel button or the Esc key is pressed. The # # script then executes the command you specified for a return of 2 - in this # # example it echos YOU CHOSE CANCEL to the terminal window. # # # # If anything else happens, the script executes the action you assigned to # # the else section - in this example it echos ERROR to the terminal window. # ############################################################################### variable=$(kdialog --warningyesnocancel "LINE1<br>LINE2";echo "$?";); if [ "$variable" = 0 ]; then echo "YOU CHOSE YES"; elif [ "$variable" = 1 ]; then echo "YOU CHOSE NO"; elif [ "$variable" = 2 ]; then echo "YOU CHOSE CANCEL"; else echo "ERROR"; fi;
Yes or no
- Example 1:
-
#!/bin/bash ############################################################################# # This script opens a Kdialog window with a single-line message that asks # # you to choose yes or no. The result of the choice you make, if any, # # determines which action the script will take. # # # # The Kdialog command returns 0 if the Enter key or the Yes button is # # pressed. In that case, the script takes the action you assigned to 0 - in # # this example it echos YOU CHOSE YES to the terminal window. # # # # The Kdialog command returns 1 if the No button is pressed or if it is # # highlighted while the Enter key is pressed. In that case, the script # # takes the action you assigned to 1 - in this example it echos YOU CHOSE # # NO to the terminal window. # # # # If anything else happens, the script takes the action you assigned to # # else - in this example it echos ERROR to the terminal window. # ############################################################################# kdialog --yesno "YES OR NO?"; if [ "$?" = 0 ]; then echo "YOU CHOSE YES"; elif [ "$?" = 1 ]; then echo "YOU CHOSE NO"; else echo "ERROR"; fi;
- Example 2:
-
#!/bin/bash ############################################################################# # This script opens a Kdialog window with a single-line message that asks # # you to choose yes or no. The result of the choice you make, if any, # # determines which action the script will take. The window has been given # # the QUESTION title. # # # # The Kdialog command returns 0 if the Enter key or the Yes button is # # pressed. In that case, the script takes the action you assigned to 0 - in # # this example it echos YOU CHOSE YES to the terminal window. # # # # The Kdialog command returns 1 if the No button is pressed or if it is # # highlighted while the Enter key is pressed. In that case, the script # # takes the action you assigned to 1 - in this example it echos YOU CHOSE # # NO to the terminal window. # # # # If anything else happens, the script takes the action you assigned to # # else - in this example it echos ERROR to the terminal window. # ############################################################################# kdialog --title "QUESTION" --yesno "YES OR NO?"; if [ "$?" = 0 ]; then echo "YOU CHOSE YES"; elif [ "$?" = 1 ]; then echo "YOU CHOSE NO"; else echo "ERROR"; fi;
- Example 3:
-
#!/bin/bash ############################################################################# # This script opens a Kdialog window with a two-line message (created by # # using an HTML <br> tag) that asks you to choose yes or no. The # # result of the choice you make, if any, determines which action the script # # will take. # # # # The Kdialog command returns 0 if the Enter key or the Yes button is # # pressed. In that case, the script takes the action you assigned to 0 - in # # this example it echos YOU CHOSE YES to the terminal window. # # # # The Kdialog command returns 1 if the No button is pressed or if it is # # highlighted while the Enter key is pressed. In that case, the script # # takes the action you assigned to 1 - in this example it echos YOU CHOSE # # NO to the terminal window. # # # # If anything else happens, the script takes the action you assigned to # # else - in this example it echos ERROR to the terminal window. # ############################################################################# kdialog --yesno "LINE1<br>LINE2"; if [ "$?" = 0 ]; then echo "YOU CHOSE YES"; elif [ "$?" = 1 ]; then echo "YOU CHOSE NO"; else echo "ERROR"; fi;
Yes or no or cancel
- Example 1:
-
#!/bin/bash ############################################################################# # This script opens a Kdialog window that displays a single-line message # # that asks you to choose yes, no, or cancel. The result of the choice you # # make, if any, determines which action the script will take. # # # # The Kdialog command returns 0 if the Enter key or the Yes button is # # pressed. In that case, the script takes the action you assigned to 0 - in # # this example it echos YOU CHOSE YES to the terminal window. # # # # The Kdialog command returns 1 if the No button is pressed or if it is # # highlighted while the Enter key is pressed. In that case, the script # # takes the action you assigned to 1 - in this example it echos YOU CHOSE # # NO to the terminal window. # # # # The Kdialog command returns 2 if the Esc key or Cancel button is pressed. # # In that case, the menu bypasses the choices and takes the action in the # # else section - in this example it echos YOU CHOSE CANCEL to the terminal # # window. # # # # If anything else happens, the script takes the action you assigned to # # else - in this example it echos ERROR to the terminal window. # ############################################################################# kdialog --yesnocancel "CHOOSE:"; variable="$?"; if [ "$variable" = 0 ]; then echo "YOU CHOSE YES"; elif [ "$variable" = 1 ]; then echo "YOU CHOSE NO"; elif [ "$variable" = 2 ]; then echo "YOU CHOSE CANCEL"; else echo "ERROR"; fi;
- Example 2:
-
#!/bin/bash ############################################################################# # This script opens a Kdialog window that displays a two-line message # # (created by using an HTML <br> tag) that asks you to choose yes, # # no, or cancel. The result of the choice you make, if any, determines # # which action the script will take. # # # # The Kdialog command returns 0 if the Enter key or the Yes button is # # pressed. In that case, the script takes the action you assigned to 0 - in # # this example it echos YOU CHOSE YES to the terminal window. # # # # The Kdialog command returns 1 if the No button is pressed or if it is # # highlighted while the Enter key is pressed. In that case, the script # # takes the action you assigned to 1 - in this example it echos YOU CHOSE # # NO to the terminal window. # # # # The Kdialog command returns 2 if the Esc key or Cancel button is pressed. # # In that case, the menu bypasses the choices and takes the action in the # # else section - in this example it echos YOU CHOSE CANCEL to the terminal # # window. # # # # If anything else happens, the script takes the action you assigned to # # else - in this example it echos ERROR to the terminal window. # ############################################################################# kdialog --yesnocancel "LINE1<br>LINE2"; variable="$?"; if [ "$variable" = 0 ]; then echo "YOU CHOSE YES"; elif [ "$variable" = 1 ]; then echo "YOU CHOSE NO"; elif [ "$variable" = 2 ]; then echo "YOU CHOSE CANCEL"; else echo "ERROR"; fi;
- Example 3:
-
#!/bin/bash ############################################################################# # This script opens a Kdialog window that displays a single-line message # # that asks you to choose yes, no, or cancel. It uses command substitution # # to put the result into a variable that is tested to determine which # # action to take. # # # # The Kdialog command returns 0 if the Enter key or the Yes button is # # pressed. In that case, the script takes the action you assigned to 0 - in # # this example it echos YOU CHOSE YES to the terminal window. # # # # The Kdialog command returns 1 if the No button is pressed or if it is # # highlighted while the Enter key is pressed. In that case, the script # # takes the action you assigned to 1 - in this example it echos YOU CHOSE # # NO to the terminal window. # # # # The Kdialog command returns 2 if the Esc key or Cancel button is pressed. # # In that case, the menu bypasses the choices and takes the action in the # # else section - in this example it echos YOU CHOSE CANCEL to the terminal # # window. # # # # If anything else happens, the script takes the action you assigned to # # else - in this example it echos ERROR to the terminal window. # ############################################################################# variable=`kdialog --yesnocancel "CHOOSE:"; echo "$?";`; if [ "$variable" = 0 ]; then echo "YOU CHOSE YES"; elif [ "$variable" = 1 ]; then echo "YOU CHOSE NO"; elif [ "$variable" = 2 ]; then echo "YOU CHOSE CANCEL"; else echo "ERROR"; fi;
- Example 4:
-
#!/bin/bash ############################################################################# # This script opens a Kdialog window that displays a single-line message # # that asks you to choose yes, no, or cancel. It uses command substitution # # to put the result into a variable that is tested to determine which # # action to take. # # # # The Kdialog command returns 0 if the Enter key or the Yes button is # # pressed. In that case, the script takes the action you assigned to 0 - in # # this example it echos YOU CHOSE YES to the terminal window. # # # # The Kdialog command returns 1 if the No button is pressed or if it is # # highlighted while the Enter key is pressed. In that case, the script # # takes the action you assigned to 1 - in this example it echos YOU CHOSE # # NO to the terminal window. # # # # The Kdialog command returns 2 if the Esc key or Cancel button is pressed. # # In that case, the menu bypasses the choices and takes the action in the # # else section - in this example it echos YOU CHOSE CANCEL to the terminal # # window. # # # # If anything else happens, the script takes the action you assigned to # # else - in this example it echos ERROR to the terminal window. # ############################################################################# variable=$(kdialog --yesnocancel "CHOOSE:"; echo "$?";); if [ "$variable" = 0 ]; then echo "YOU CHOSE YES"; elif [ "$variable" = 1 ]; then echo "YOU CHOSE NO"; elif [ "$variable" = 2 ]; then echo "YOU CHOSE CANCEL"; else echo "ERROR"; fi;
See also:
Obligatory Happy Ending
And they all lived happily ever after. The end.

With regard to your first line you can also do this.
With a file which has two (maybe more but not tested) columns you can, pipe the file though kdialog –menu “Select a language:”
New command line.
kdialog –menu “select your course: ” $(cat ClassesAvailable) –geometry 700×400
where the ClassesAvailable file contains:
a French
b English
c German
d Chinese
You get the same result.
Comment by ompaul — April 5, 2011 @ 9:08 am
Thanks! I’ve added it above under Menu (alternate method).
Comment by mostlylinux — April 6, 2011 @ 12:23 pm
How do you get the list and coloum option available in zenity under kdialog. Kdialog looks really great but there are no proper tutorial (with example) available on the internet.
I am writing a bash script with GUI both zenity and kdialog so as to avoid no dependency error. I have completed the zenity part sucessfully but struggling in kdialog, especially in list and coloum (available in zenity). If you know more about kdialog please share with us.
Thanks and regards,
sundar_ima
Comment by sundar_ima — April 13, 2011 @ 4:23 pm
I think the closest thing KDialog has to Zenity’s list and column would be the –menu option shown at the top of this page. From everything I’ve been able to find out, KDialog is not as comprehensive as Zenity. Maybe the official KDE TechBase KDialog tutorial will help.
Linux Magazine did a brief overview comparison of KDialog and Zenity that shows what each is capable of. Enjoy!
Comment by mostlylinux — April 14, 2011 @ 1:00 pm