How to show a GUI message box from a bash script in linux? How to show a GUI message box from a bash script in linux? bash bash

How to show a GUI message box from a bash script in linux?


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!


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.


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

gxmessage "my text"

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 ?).

xmessage -buttons Ok:0,"Not sure":1,Cancel:2 -default Ok -nearmouse "Is xmessage enough for the job ?" -timeout 10

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.

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"

Others not in Ubuntu standard repositories

  • shellgui
  • xdialog
  • gtkdialog

Off-topic (for terminal)

whiptail --msgbox "my text" 10 20dialog --msgbox "my text" 10 20

Feel free to edit.