kdialog
Display KDE dialog boxes from shell scripts
TLDR
Open a dialog box displaying a specific message
Open a question dialog with a yes and no button, returning 0 and 1, respectively
Open a warning dialog with a yes, no, and cancel button, returning 0, 1, or 2 respectively
Open an input dialog box and print the input to stdout when OK is pressed
Open a dialog to prompt for a specific password and print it to stdout
Open a dialog containing a specific dropdown menu and print the selected item to stdout
Open a file chooser dialog and print the selected file's path to stdout
Open a progressbar dialog and print a D-Bus reference for communication to stdout
SYNOPSIS
kdialog [options]
Example: kdialog --title "Simple Message" --msgbox "Hello, this is a kdialog message!"
Example: kdialog --inputbox "What is your name?" "Guest"
PARAMETERS
--title text
Sets the title of the dialog window.
--msgbox text
Displays a simple message box with an 'OK' button. Returns 0 on 'OK'.
--yesno text
Displays a message box with 'Yes' and 'No' buttons. Returns 0 for 'Yes', 1 for 'No'.
--inputbox text [default]
Displays a text input box. Outputs the entered text to standard output.
--password
Displays a password input box (text hidden). Outputs the entered password to standard output.
--textbox file
Displays the content of a specified file in a scrollable text viewer.
--progressbar text
Displays a progress bar with a label. Progress can be updated by sending commands to kdialog's standard input.
--notification text
Shows a passive desktop notification (pop-up) with the given text.
--passivepopup text [delay]
Shows a transient popup message that disappears after a specified delay in seconds (default 5s).
--getopenfilename [path] [filter]
Displays a file selection dialog for opening files. Outputs the selected file path.
--getsavename [path] [filter]
Displays a file selection dialog for saving files. Outputs the selected file path.
--getexistingdirectory [path]
Displays a directory selection dialog. Outputs the selected directory path.
--menu text tag1 item1 ...
Displays a menu list. Outputs the tag of the selected item.
--checklist text tag1 item1 state1 ...
Displays a checklist. Outputs the tags of selected items, separated by --results-separator (if specified).
--radiolist text tag1 item1 state1 ...
Displays a radio button list (single selection). Outputs the tag of the selected item.
--combobox text item1 item2 ...
Displays a dropdown combobox. Outputs the selected item.
--getcolor [color]
Displays a color picker. Outputs the selected color in RGB hex format (e.g., #RRGGBB).
--getfont [font]
Displays a font selector. Outputs the selected font description string (e.g., 'Sans,10,-1,5,50,0,0,0,0,0').
--geometry widthxheight+x+y
Sets the initial size and position of the dialog window.
--always-on-top
Keeps the dialog window visible on top of other windows.
--version
Displays the kdialog version information and exits.
--help
Displays a concise help message with common options and exits.
DESCRIPTION
kdialog is a powerful utility for displaying user-friendly graphical dialog boxes from shell scripts or command-line applications within the KDE desktop environment. It offers a simple and efficient way to interact with users without requiring complex GUI programming. Script writers can leverage kdialog to present various types of dialogs, including informational messages, warnings, errors, yes/no questions, text input fields, password prompts, file/directory selectors, color pickers, font choosers, and different types of list-based selections (e.g., menus, checklists, radiolists).
The command outputs user selections or entered data to standard output and indicates user actions (e.g., OK, Cancel, Yes, No) via its exit code. This makes kdialog an invaluable tool for creating interactive and automated scripts in a graphical Linux environment, especially for users of KDE Plasma. It serves a purpose similar to zenity for GNOME or dialog for console-based interfaces.
CAVEATS
KDE/Qt Dependency: kdialog is tightly integrated with the KDE desktop environment and relies on the Qt toolkit. It will not function on systems where KDE/Qt libraries are not installed or in purely command-line environments (e.g., SSH sessions without X forwarding).
Graphical Environment Required: It necessitates a running X server or Wayland compositor to display its dialogs.
Blocking Behavior: Most kdialog calls are blocking, meaning the script execution will pause until the user interacts with and closes the dialog window.
Limited Customization: While versatile, it offers less granular visual customization compared to building a full-fledged GUI application.
RETURN CODES
kdialog typically returns a specific exit code to indicate the user's action: 0 for success (e.g., 'OK', 'Yes'), 1 for 'No', and other non-zero values (e.g., 2, 255) for 'Cancel' or errors. These codes can be checked in shell scripts using the $? variable immediately after the kdialog command.
STANDARD OUTPUT USAGE
For dialog types that solicit user input (e.g., --inputbox, --getopenfilename, --menu), the selected value or entered text is printed to kdialog's standard output (stdout). This allows shell scripts to easily capture and process the user's response using command substitution (e.g., `variable=$(kdialog --inputbox "Prompt:")`).
STANDARD ERROR FOR MESSAGES
Any error messages, warnings, or debug information generated by kdialog itself are typically outputted to standard error (stderr), keeping stdout clean for the intended user input.
HISTORY
kdialog has been a core utility within the KDE desktop environment since its early iterations, providing a crucial bridge between command-line scripting and graphical user interfaces. Its development has paralleled that of KDE itself, leveraging advancements in the Qt toolkit to offer robust and user-friendly dialog capabilities. It embodies KDE's philosophy of empowering users with accessible scripting tools, enabling them to create interactive experiences and automate tasks without needing to write complex GUI application code. Its focus on simplicity and direct functionality has made it a valuable asset for quick prompts, file selections, and user feedback in the KDE ecosystem.
SEE ALSO
zenity(1), dialog(1), xdialog(1), notify-send(1)