Making KDE dialogue boxes appear from shell scripts

  • December 21, 2007
  • Avatar for peter
    Peter
    Upfold

Providing graphical feedback in the form of dialogue boxes when you're writing a shell script isn't really that easy to do yourself. If you're a KDE user, though, and want to write a shell script that gives you feedback in the form of one of these.

FOSSwire KDialog

This could be really useful if you want to set up a script that you want to be able to run graphically, for example, by making a link on your desktop to run it.

So how does this all work? The secret is a program called KDialog. It should be installed with recent KDE versions, but if not, install the package kdialog from your package manager.

Making a simple dialogue box appear is pretty simple. To use the example above, I just needed this command:

$ kdialog --title FOSSwire --msgbox "FOSSwire is awesome"

And that's it. Note the double quotes around the main message - if you have any spaces or special characters in either the title or the main text, you'll need to quote it to prevent the shell choking on the space and thinking it's another argument.

As well as msgbox, there are also other types of dialogue you can experiment with creating. For example, you can use a text box to get textual input from the user, which is returned as the application's output. This means you can use it to gather some information from the user and use that later in the script.

$ kdialog --title FOSSwire --textinputbox "Enter some text"

Enter text dialogue

Also available are options for creating yes/no dialogues, error boxes and much more. To find out exactly which type of alert would best suit you, simply run kdialog without any options to see the list of options.

And have fun GUI-fying your scripts with KDE!

Avatar for peter Peter Upfold

Home » Articles »