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
if nothing else is present. you can launch an xterm and echo in it, like this:
xterm -e bash -c 'echo "this is the message";echo;echo -n "press enter to continue "; stty sane -echo;answer=$( while ! head -c 1;do true ;done);'
alert
and notify-send
seem to be the same thing. I use notify-send
for non-input messages as it doesn't steal focus and I cannot find a way to stop zenity etc. from doing this.
e.g.
# This will display message and then disappear after a delay:
notify-send "job complete"
# This will display message and stay on-screen until clicked:
notify-send -u critical "job complete"
Zenity is really the exact tool that I think that you are looking for.
or
zenity --help
I found the xmessage command, which is sort of good enough.
How about Ubuntu's alert. It can be used after any operation to alert it finished and even show red cross icon if operaton was finnished with errors
ls -la; alert
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:
my_variable=$(zenity --entry)
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:
my_variable=$(zenity --entry --text="What's my variable:")
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.
my_date=$(zenity --calendar)
Which gives a nicely formatted date based on what the user clicked on:
echo ${my_date}
gives:
08/05/2009
There are also options for slider selectors, errors, lists and so on.
Hope this helps.