Dialog from bash script
There is
- dialog (ncurses based)
- xdialog (X11 based)
Other implementations are reported to exist:
- zenity (Gnome)
- kdialog (Kde)
If you use gpm
, you can even use the mouse in a console environment. It requires a tty, so it will work over ssh, screen, xterm etc. but not when piping/redirecting.
Both sport more or less the same interface so you can switch depending on whether an X display is available
Here is a dialog script that displays a simple YES/NO box:
#!/bin/bash
DIALOG=${DIALOG=dialog}
$DIALOG --title " My first dialog" --clear \
--yesno "Hello , this is my first dialog program" 10 30
case $? in
0)
echo "Yes chosen.";;
1)
echo "No chosen.";;
255)
echo "ESC pressed.";;
esac
Replacing dialog
by xdialog
:
I've searched what dialog creators are. I found yad and with this I can set my desired options:
yad --skip-taskbar --center --title="Print dialog" {--image,--window-icon}=/usr/share/icons/Tango/72x72/devices/printer1.png --form --item-separator=, --field="Pages per sheet":CB 1,2,4,6,8 --field="Pages"
And when I choose "2 pages per sheet" and pages "1-12" and after click OK
the output will 2|1-12|
.
This is what I desired. Zenity or Xdialog can do similar?