1

Following this solution I have a zenity script to ask me what to do when clicking an executable script in Thunar or a desktop file in 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

And it shows this:

enter image description here

But there is a small glitch: you cannot dismiss the dialog at this point: using close window button, Esc or Alt+F4 equates to the --cancel-label option in the script and will open the file in text editor.

How could I edit the script so that when Esc is pressed the zenity windows would close without farther action?


Edit after comment:

I have got this in a comment:

either let the --question dialog --timeout to get a third return value (5)

Indeed, --timeout=4 will close the dialog after that number of secs.

or you can go for multiple choice dialog by --list --radiolist

What does that mean?

  • 3
    I had an answer typed out for you over at U&L and then you deleted your question... very funny. Anyhow, you can either let the --question dialog --timeout to get a third return value (5) or you can go for multiple choice dialog by --list --radiolist. Have fun. – frostschutz Mar 02 '17 at 13:47
  • @frostschutz - Leaving back what's gone: I would very much appreciate you posting an answer here with all the details. Giving examples would not only help me with what I ask here, but would give me some clues for other uses of zenity :) - what I know now about it is pretty much the script above. let the --question dialog --timeout to get a third return value (5) it's something that needs an interpretation for me. –  Mar 02 '17 at 14:20
  • Could easily make a small Gtk window with any keybinding you want. :) – Jacob Vlijm Nov 24 '17 at 16:05

2 Answers2

1

A simplified script that uses yad can be a workaround in order to have the window dismissed as intended; labels are 'OK' for run and 'Cancel' for edit.

sudo apt install yad

And the script is:

#!/bin/bash

yad --text="Execute the file? (press 'Cancel' to edit)" 

case $? in
    0)thunar "$1"
    ;;
    1)gedit $1
    ;;
esac

enter image description here


A version of the initial script (somewhat improved based on the comment), which even in absence of action will close the window after a number of seconds:

#!/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 

enter image description here

derHugo
  • 3,356
  • 5
  • 31
  • 51
1

Simple example of a radiolist

There is a simple example of a radiolist in this link,

http://linux.byexamples.com/archives/265/a-complete-zenity-dialog-examples-2/

Example with --list

I think it is easier to use a simple list (with the option --list but without --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=

enter image description here

sudodus
  • 46,324
  • 5
  • 88
  • 152