IT story

리눅스의 bash 스크립트에서 GUI 메시지 상자를 표시하는 방법은 무엇입니까?

hot-time 2020. 6. 21. 19:24
반응형

리눅스의 bash 스크립트에서 GUI 메시지 상자를 표시하는 방법은 무엇입니까?


우분투 리눅스에서 작은 bash 스크립트를 작성하고 있습니다. 입력을 입력하거나 출력을 볼 수있는 터미널 창이 필요없이 GUI에서 실행할 수 있기를 원합니다.

지금까지 필요한 유일한 입력은 sudo의 비밀번호이며 gksudo는이를 잘 처리합니다. 그러나 아직 메시지 상자를 표시하는 쉬운 방법을 찾지 못했습니다. 사용 가능한 'gkmessage'명령이 있습니까? 기본 우분투 설치에 존재하는 것을 선호하지만 필요한 경우 새 패키지를 설치하는 것은 중요하지 않습니다.


나는 Zenity 가 당신이 원하는 것을 할 것이라고 믿습니다 . 커맨드 라인에서 GTK 대화 상자를 표시하도록 특별히 설계되었으며 Ubuntu 패키지 로 사용할 수 있습니다 .


당신이 사용하는 경우 우분투에게 많은 배포판을 notify-send명령은 오른쪽 상단 모서리에있는 그 좋은 부패하기 쉬운 통지 중 하나를 던질 것이다. 이렇게 :

notify-send "My name is bash and I rock da house"

아름다운!


모두가 선량함을 언급하는데, 다른 많은 사람들이있는 것 같습니다. 혼란 스럽지만 흥미로운 목록은 http://alternativeto.net/software/zenity/에 있습니다.

먼저, 텍스트 서식 마크 업, 창 제목, 단추 레이블이 포함 된 zenity의 예입니다.

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매우 오래되어 안정적이며 X를 사용하는 모든 배포판에서 사용할 수 있습니다 (X와 함께 배포되므로). X 리소스를 통해 커스터마이징이 가능합니다. Linux 또는 Unix를 오랫동안 사용해온 사람들은 그것이 무엇을 의미하는지 알 수 있습니다 ( .Xdefaults누구나?).

xmessage -buttons Ok:0,"Not sure":1,Cancel:2 -default Ok -nearmouse "Is xmessage enough for the job ?" -timeout 10

kdialog

(검증되지 않은)

PPA에서

YAD : 스테로이드 온전함 [쉘 스크립트에서 그래픽 대화 상자 표시] ~ 웹 Upd8 : Ubuntu / Linux 블로그 . 대화 상자의 크기를 자동으로 조정하지 않는 것 같습니다.

echo My text | yad \
--text-info \
--width=400 \
--height=200

더 큰 예

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"

Ubuntu 표준 리포지토리에없는 기타

  • shellgui
  • xdialog
  • gtkdialog

주 제외 (터미널 용)

whiptail --msgbox "my text" 10 20
dialog --msgbox "my text" 10 20

자유롭게 편집하십시오.


zenity의 응용 프로그램이 나타납니다 당신이 찾고있는 무엇을 할 수 있습니다.

zenity 에서 입력을 받으려면 변수를 지정하고 zenity --entry 출력을 저장하십시오. 다음과 같이 보입니다 :

my_variable=$(zenity --entry)

my_variable 의 값을 보면 zenity pop-up entry 대화 상자에 입력 된 값이됩니다.

If you want to give some sort of prompt as to what the user (or you) should enter in the dialog, add the --text switch with the label that you want. It looks something like this:

my_variable=$(zenity --entry --text="What's my variable:")

Zenity has lot of other nice options that are for specific tasks, so you might want to check those out as well with zenity --help. One example is the --calendar option that let's you select a date from a graphical calendar.

my_date=$(zenity --calendar)

Which gives a nicely formatted date based on what the user clicked on:

echo ${my_date}

gives:

08/05/2009

There are also options for slider selectors, errors, lists and so on.

Hope this helps.


I found the xmessage command, which is sort of good enough.


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"`

alert and notify-send seem to be the same thing. I use notify-send for non-input messages as it doesn't steal focus and I cannot find a way to stop zenity etc. from doing this.

e.g.

# This will display message and then disappear after a delay:
notify-send "job complete"

# This will display message and stay on-screen until clicked:
notify-send -u critical "job complete"

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


How about Ubuntu's alert. It can be used after any operation to alert it finished and even show red cross icon if operaton was finnished with errors

ls -la; alert

if nothing else is present. you can launch an xterm and echo in it, like this:

 xterm -e bash -c 'echo "this is the message";echo;echo -n "press enter to continue "; stty sane -echo;answer=$( while ! head -c 1;do true ;done);'

Zenity is really the exact tool that I think that you are looking for.

or

zenity --help

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

참고URL : https://stackoverflow.com/questions/7035/how-to-show-a-gui-message-box-from-a-bash-script-in-linux

반응형