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 you are using Ubuntu many distros the notify-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!
There is also dialog and the KDE version kdialog. dialog is used by slackware, so it might not be immediately available on other distributions.
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.
zenity \
--info \
--text="<span size=\"xx-large\">Time is $(date +%Hh%M).</span>\n\nGet your <b>coffee</b>." \
--title="Coffee time" \
--ok-label="Sip"
gxmessage "my text"
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 ?).
xmessage -buttons Ok:0,"Not sure":1,Cancel:2 -default Ok -nearmouse "Is xmessage enough for the job ?" -timeout 10
(not tested)
YAD: Zenity On Steroids [Display Graphical Dialogs From Shell Scripts] ~ Web Upd8: Ubuntu / Linux blog. Does not seem to auto-size dialogs.
echo My text | yad \
--text-info \
--width=400 \
--height=200
An bigger example
yad \
--title="Desktop entry editor" \
--text="Simple desktop entry editor" \
--form \
--field="Type:CB" \
--field="Name" \
--field="Generic name" \
--field="Comment" \
--field="Command:FL" \
--field="Icon" \
--field="In terminal:CHK" \
--field="Startup notify:CHK" "Application" "Name" "Generic name" "This is the comment" "/usr/bin/yad" "yad" FALSE TRUE \
--button="WebUpd8:2" \
--button="gtk-ok:0" \
--button="gtk-cancel:1"
whiptail --msgbox "my text" 10 20
dialog --msgbox "my text" 10 20
Feel free to edit.
Example bash script for using Gambas GTK/QT Controls(GUI Objects):
The Gambas IDE can be used to design even large GUIs and act as a GUI server.
Example expplications can be downloaded from the Gambas App store.
https://gambas.one/gambasfarm/?id=823&action=search
Kdialog and dialog are both good, but I'd recommend Zenity. Quick, easy, and much better looking the xmessage or dialog.
Here's a little Tcl script that will do what you want. The Wish interpreter should be installed by default on Ubuntu.
#!/usr/bin/wish
pack [label .msg -text [lindex $argv 0]]
pack [entry .ent]
bind .ent <KeyPress-Return> { puts [.ent get]; destroy . }
focus .ent
Call it like this:
myanswer=`gui-prompt "type your answer and press enter"`