Zenity脚本:使用关闭(x)按钮或Esc关闭窗口
在这个解决方案之后,我有一个zenity脚本来询问我在Thunar中单击可执行脚本或Pantheon Files中的桌面文件 时该怎么做 :
#!/bin/bash zenity --question --text="What to do?" \ --ok-label=Run \ --cancel-label=Edit case $? in 0)thunar "$1" ;; 1)gedit $1 ;; esac
它显示了这个:
但是有一个小故障:你不能在这一点上忽略对话框:使用关闭窗口按钮, Esc或Alt + F4等同于脚本中的--cancel-label
选项,并将在文本编辑器中打开文件。
我怎么能编辑脚本,这样当按下Esc时,zenity窗口会关闭而不会进一步动作?
评论后编辑:
我在评论中得到了这个:
让–question对话框–timeout得到第三个返回值(5)
实际上, – --timeout=4
将在该--timeout=4
后关闭对话框。
或者你可以通过–list –radiolist进行多选对话
那是什么意思?
放射学家的简单例子
在这个链接中有一个简单的放射学家的例子,
http://linux.byexamples.com/archives/265/a-complete-zenity-dialog-examples-2/
带–list的示例
我认为使用一个简单的列表更容易(使用选项--list
但没有--radiolist
)
$ ans=$(zenity --list --title "What to do?" --column "What to do?" Run Edit 2> /dev/null); echo "ans=$ans" ans=Run $ ans=$(zenity --list --title "What to do?" --column "What to do?" Run Edit 2> /dev/null); echo "ans=$ans" ans=Edit $ ans=$(zenity --list --title "What to do?" --column "What to do?" Run Edit 2> /dev/null); echo "ans=$ans" ans=
使用yad
简化脚本可以是一种解决方法,以使窗口按预期被解除; 运行时标签为“OK”,编辑为“取消”。
sudo apt install yad
脚本是:
#!/bin/bash yad --text="Execute the file? (press 'Cancel' to edit)" case $? in 0)thunar "$1" ;; 1)gedit $1 ;; esac
初始脚本的一个版本(基于注释稍微改进),即使没有操作,也会在几秒钟后关闭窗口:
#!/bin/bash zenity --question --text="Press RUN to execute -- Press EDIT, ESC or close (x) to open as text -- or WAIT 7 seconds to dismiss" \ --ok-label=RUN \ --cancel-label=EDIT \ --timeout=7 case $? in 0)thunar $1 ;; 1)gedit $1 ;; esac