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

前端 未结 13 2162
孤街浪徒
孤街浪徒 2020-12-04 04:58

I\'m writing a few little bash scripts under Ubuntu linux. I want to be able to run them from the GUI without needing a terminal window to enter any input or view any output

相关标签:
13条回答
  • 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!

    0 讨论(0)
  • 2020-12-04 05:43

    There is also dialog and the KDE version kdialog. dialog is used by slackware, so it might not be immediately available on other distributions.

    0 讨论(0)
  • 2020-12-04 05:44

    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 20
    dialog --msgbox "my text" 10 20
    

    Feel free to edit.

    0 讨论(0)
  • 2020-12-04 05:50

    Example bash script for using Gambas GTK/QT Controls(GUI Objects): The Gambas IDE can be used to design even large GUIs and act as a GUI server. Example expplications can be downloaded from the Gambas App store.
    https://gambas.one/gambasfarm/?id=823&action=search

    0 讨论(0)
  • 2020-12-04 05:54

    Kdialog and dialog are both good, but I'd recommend Zenity. Quick, easy, and much better looking the xmessage or dialog.

    0 讨论(0)
  • 2020-12-04 05:55

    Here's a little Tcl script that will do what you want. The Wish interpreter should be installed by default on Ubuntu.

    #!/usr/bin/wish
    pack [label .msg -text [lindex $argv 0]]
    pack [entry .ent]
    bind .ent <KeyPress-Return> { puts [.ent get]; destroy . }
    focus .ent
    

    Call it like this:

    myanswer=`gui-prompt "type your answer and press enter"`
    
    0 讨论(0)
提交回复
热议问题