Every GUI program has its command line, even dialog boxes too. zenity for gnome, kdialog for KDE, xmessage for other windows managers, etc.
In this example I am going to show you examples of xmessage and zenity.
xmessage is a very simple dialog box which uses by fluxbox, it allows you to define your text and buttons. Let say I want to create a shutdown script, before execute the shutdown, I would like to ask for comfirmation.
xmessage "Are you sure you want to shutdown? " -buttons yes,no
This will shows a simple dialog with 2 buttons, if user click yes, it returns 101, if no returns 102. To check the return value, do this
You can ask xmessage to return the button label string, so you can store the label and manipulate the function.
answer=$(xmessage "Are you sure you want to shutdown? " -buttons yes,no -print)
User click yes, answer will store “yes”. Checks the value with echo
zenity is more complete, it support various dialogs, question, notification, calendar, error etc. My example make use of question.
To load various types of dialog, just specified the types. Check the types by –help or simple man zenity. For this case, I want to use –question.
zenity --question --text "Are you sure you want to shutdown?"
The question dialog for zenity consist of “ok” and “cancel” buttons. Its button and return value are fixed. When user click “ok” it returns 0, “cancel” returns 1.
zenity allows you to specified you title.
zenity --title "Shutdown Comfirmation" --question --text "Are you sure you want to shutdown?"
Check out the sample scripts at Beyond the Sky