119

How can I create a message box from the command line, either GUI message boxes or message boxes shown inside the terminal?

It would also be interesting to be able to get a simple input back from the user, for example, an input given with radio buttons (yes/no, OK, etc).

4 Answers4

179

For a standard "box around a message", use boxes:

echo 'This is a test' | boxes

boxes will look like this (First one. Second one is a custom like cowsay):

Screenshot of an asterix box and an ASCII-art dog holding a sign of text


If you mean an alert box, use notify-send:

notify-send 'title' 'message'

notify-send looks like this:

Pop-up message reading "Hello Ashframe..."


You also can use zenity for a popup window:

zenity --error --text="An error occurred\!" --title="Warning\!"

Zenity is more graphical and has more options, like having the window appear as a question, using:

zenity --question --text="Do you wish to continue/?"

or even progress bars, using:

find /usr | zenity --progress --pulsate --auto-close --auto-kill --text="Working..."

zenity looks like this:

error, question, info, and warning dialog boxes with buttons


Or use dialog, for a command-line only message box:

dialog --checklist "Choose OS:" 15 40 5 \
1 Linux off \
2 Solaris on \
3 'HP UX' off \
4 AIX off

dialog looks like this:

dialog TUI with 4 options


Another option is whiptail:

whiptail --title "Example Dialog" --msgbox "This is an example of a message box. You must hit OK to continue." 8 78

whiptail looks like this:

whiptail pop-up box with two text buttons


And if you are truly crazy, use toilet:

toilet -F border -F gay "CRAZY"

toilet looks like this:

colorful text box reading "CRAZY"

Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255
polym
  • 10,852
59

xmessage

This is the granddaddy of GUI alerts:

xmessage -center "Hello, World!"

Pure retro goodness.

I also bet that it should be widely available on X11 systems.

SO thread: How to show a GUI message box from a bash script in linux? | Stack Overflow

Tested in Ubuntu 18.04.

Ciro Santilli OurBigBook.com
  • 18,092
  • 4
  • 117
  • 102
  • 4
    xmessage is even installed on Ubuntu Server by default. So I can use ssh -Y <host> to log into the machine while forwarding x connections and then run some-command; xmessage "some-command is done" to pop up a notification on my desktop when the long running command is finished. – Stephen Ostermiller May 03 '19 at 20:30
  • @StephenOstermiller yes, that is a good tip! – Ciro Santilli OurBigBook.com May 03 '19 at 21:27
  • 1
    Cool command. To auto-clear the message after a few seconds: xmessage -timeout 10 "Goodbye in 10s!". – AlainD Sep 11 '19 at 15:49
  • 4
    TINY on a 4k monitor. – Gringo Suave Feb 20 '20 at 21:15
  • 1
    This will do wonders for my long-running rsync commands over ssh. – Sridhar Sarnobat Nov 19 '20 at 20:10
  • 1
    Xmessage is a very underestimated little program. You can also use buttons that return different exit status. E.g.: xmessage -button OK:0,Cancel:101 Hello; echo $? returns 0 (success) if user presses OK and 101 if he presses cancel. – Quasímodo Nov 11 '21 at 18:45
  • 1
    On the fonts issue: fonts can be configured. Font size can be changed with xmessage -fn '-*-*-*-r-*-*-26-*-*-*-*-*-*-*' 'My message', use xfontsel for a good tool to find a good font. – Real Nov 29 '21 at 14:13
  • Default xmessage fonts can also be set permanently on .Xresources file on user home, by adding for example Xmessage*font: -*-*-*-r-*-*-26-*-*-*-*-*-*-* to the file. – Real Nov 29 '21 at 14:51
  • It would be nice if distributions automatically set nice settings (depending on resolution, fonts and locale) using .Xdefaults or .Xresources to improve readability on all devices. – Real Nov 29 '21 at 14:52
  • 1
    Where there is red |||| lines at the beginning of the line? – alper Jan 21 '23 at 14:53
  • @alper I think it must have been fashionable in the 80s. – Ciro Santilli OurBigBook.com Jan 21 '23 at 17:55
13

And then just because @polym's completely over the top answer missed the classic messaging:

write <username> [<terminal>] - send a message to another user. Either interactively or as part of a pipe with echo "message" | write username

write


And the complement to write, wall to send a message to all users

wall

HBruijn
  • 7,418
4

If you are willing to pipe the text to a Python wrapper, you can use terminaltables:

pip3 install colorclass
pip3 install terminaltables

Then in the GitHub Repo, you can use one of the examples to write a python wrapper.

enter image description here

not2qubit
  • 1,666
  • -1 for requiring something as heavy as python, pip and then some packages. – einpoklum Jan 23 '24 at 16:54
  • @einpoklum That's a poor argument, especially since most examples above require the installation of entire new packages and tools, while nearly all people already have python installed. – not2qubit Jan 24 '24 at 12:54