4

YAD is a Zenity fork.

I have this yad script:

#!/bin/bash

yad --text="Execute the file? (press 'Cancel' to open in text editor)" 

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

Associated with a desktop file as application launcher, it can be used to display a window when clicking a file (e.g. a script, etc).

enter image description here

In zenity, the name of the labels can be edited:

The same script with Zenity should look like so:

#!/bin/bash

zenity --question --text="What to do?" \
       --ok-label=Run \
       --cancel-label=Edit

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

And Run and Edit can be changed.

I think that here it says that yad has means to edit the labels:

--button=BUTTON:ID

Add the dialog button. May be used multiply times. ID is an exit code or a command. BUTTON may be gtk stock item name for predefined

buttons (like gtk-close or gtk-ok) or text in a form LABEL[!ICON[!TOOLTIP]] where `!' is an item separator. Full list of stock items may be found in gtk-demo program, in snippet called "Stock Items and Icon Browser". If no buttons specified OK and Cancel buttons used. See Exit Status section for more. If ID have a non-numeric value it treats like a command and click on such button doesn't close the dialog.

But I'm not sure. And I don't know what to make of that info. I need an example on how the buttons of my yad script above may have their names changed.

I have reasons to use yad instead of zenity - the zenity script cannot me dismissed with close or Esc.

derHugo
  • 3,356
  • 5
  • 31
  • 51

2 Answers2

5

I am not totally sure what you mean, but if I understand it correctly you want something like this:

#!/bin/bash

yad --text="Execute the file?" --button="Execute" --button="Edit"

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

I found a link (ubuntuusers.de), but it is in German. There are a few code examples and pictures though, that might help. And you can always translate it with google.

I would have written this as a comment if I could, but I am not yet allowed to. Hope it helps.

Sergiy Kolodyazhnyy
  • 105,154
  • 20
  • 279
  • 497
jarleih
  • 696
2

I happened to write this a few days ago for a question of my own (Bash template to use zenity (or yad) to insert / edit / delete records in a file or database) and thought it was worth sharing:

websync 1

Notice the six buttons on the screen and how they are handled in the code below (sorry still a work in progress). An important note is when using custom buttons to always trap default return codes like 252 for Escape and Windows close (clicking X).

while true ; do

Record=(`yad \
    --title "websync - Compare local scripts to those published on internet." --list \
        --text '<span foreground="blue" font="14">Toggle select next to file then click action button</span>' \
        --width=900 --height=600 --center --radiolist -separator="$IFS" --no-click \
        --button="Insert before":1 --button=Edit:2 --button=Delete:3 --button=Run:4 \
        --button="Cancel ALL":5 --button=Save:6 --search-column=3 \
        --column "Select" --column "Record number" --hide-column=2 --column "File Name" \
        --column "Status" --column " Website Address" \
        "${choices[@]}"`)
Action=$?

RecSelected=false
RecArr=()
i=0

# With radio list only one choice is possible
for Field in "${Record[@]}" ; do
    RecSelected=true
    RecArr[i]=$Field
# echo "RecArr $i ${RecArr[$i]}"
    ((i++))
done

echo "button: $Action"# 
# Note: When X closes window or Escape pressed 252 is returned.

# Insert before || or Edit ?
if [[ $Action == 1 ]] || [[ $Action == 2 ]] ; then
    RecArr[3]="New"
    # --text="Set fields and click OK to update" 
    # Note if there is a space at end of line, next line generates invalid command error from yad
    yad --width=600 --height=400 --title="Link file to Website Address" \
        --form --center \
        --field="Record Number":RO --field="File name":FL --field="Status":RO \
        --field="Website Address":TXT \
        ${RecArr[1]} ${RecArr[2]} ${RecArr[3]} ${RecArr[4]}
    ret=$?

    # Cancel =252, OK = 0
    if [[ $ret == 0 ]] ; then
        # Update array and renumber
        : # noop
    else
        continue # cancel changes.
    fi

elif [[ $Action == 3 ]] ; then
    : # Delete
elif [[ $Action == 4 ]] ; then
    : # Run
elif [[ $Action == 5 ]] || [[ $Action == 252 ]] ; then
    # Cancel ALL || or X the window or Escape
    exit
elif [[ $Action == 6 ]] ; then
    # Save
    exit
else
    zenity --error --text "~/bin/websync - Unknown button return code: $Action"
fi

done # End of while loop