I'm writing a few little bash scripts under Ubuntu linux. I want to be able to run them from the GUI without needing a terminal window to enter any input or view any output.
So far the only input required is a password for sudo - and gksudo handles that fine. But I haven't found an easy way to show a message box yet. Is there some kind of 'gkmessage' command available? I'd prefer something present in a default Ubuntu install, but I don't mind installing a new package if necessary.
I found the xmessage command, which is sort of good enough.
If you are using
Ubuntumany distros thenotify-send
command will throw one of those nice perishable notifications in the top right corner. Like so:notify-send "My name is bash and I rock da house"
B.e.a.utiful!
The zenity application appears to be what you are looking for.
To take input from zenity, you can specify a variable and have the output of zenity --entry saved to it. It looks something like this:
If you look at the value in my_variable now, it will be whatever was typed in the zenity pop up entry dialog.
If you want to give some sort of prompt as to what the user (or you) should enter in the dialog, add the --text switch with the label that you want. It looks something like this:
Zenity has lot of other nice options that are for specific tasks, so you might want to check those out as well with zenity --help. One example is the --calendar option that let's you select a date from a graphical calendar.
Which gives a nicely formatted date based on what the user clicked on:
gives:
There are also options for slider selectors, errors, lists and so on.
Hope this helps.
Everyone mentions zenity, there seem to be many others. A mixed up but interesting list is at http://alternativeto.net/software/zenity/
First, an example of zenity featuring text formatting markup, window title, button label.
gxmessage
xmessage
xmessage
is very old so it is stable and probably available in all distributions that use X (since it's distributed with X). It is customizable through X resources, for those that have been using Linux or Unix for long enough to know what it means (.Xdefaults
, anyone ?).kdialog
(not tested)
In a PPA
YAD: Zenity On Steroids [Display Graphical Dialogs From Shell Scripts] ~ Web Upd8: Ubuntu / Linux blog. Does not seem to auto-size dialogs.
An bigger example
Others not in Ubuntu standard repositories
Off-topic (for terminal)
Feel free to edit.
if nothing else is present. you can launch an xterm and echo in it, like this:
I believe Zenity will do what you want. It's specifically designed for displaying GTK dialogs from the command line, and it's available as an Ubuntu package.