Dialog from bash script

2019-01-18 11:46发布

I want create a simple graphical (Qt, Gtk, ...) dialog, concretly a simple print dialog, as a "frontend" to lpr, in bash. What I want? How many pages per page, printing interval. It's (at least) two options.

What is the best util(s) to solve this problem?

5条回答
爷的心禁止访问
2楼-- · 2019-01-18 12:16

matedialog (AKA mate-dialog) uses GTK+. It may also be the only script GUI dialog tool available under Cygwin.

查看更多
Anthone
3楼-- · 2019-01-18 12:17

There is

Other implementations are reported to exist:

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

enter image description here

Replacing dialog by xdialog:

enter image description here

查看更多
可以哭但决不认输i
4楼-- · 2019-01-18 12:21

You could use gdialog in gnome/ubuntu. I can't find xdialog anymore in 14.10. The answer from @sehe works with it just change dialog for gdialog.

查看更多
够拽才男人
5楼-- · 2019-01-18 12:23

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"

Dialog

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?

查看更多
一纸荒年 Trace。
6楼-- · 2019-01-18 12:24

Whiptail displays user-friendly dialog boxes from shell scripts

Whiptail is a dialog replacement using newt instead of ncurses. It provides a method for displaying several different types of dialogue boxes from shell scripts. This allows a script developer to interact with the user in a much friendlier manner.

whiptail example

查看更多
登录 后发表回答