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

前端 未结 13 2164
孤街浪徒
孤街浪徒 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条回答
  •  醉梦人生
    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="Time is $(date +%Hh%M).\n\nGet your coffee." \
    --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.

提交回复
热议问题