Page 1 of 1

How to capture button click in YAD? SOLVED

Posted: Thu Dec 23, 2021 7:43 pm
by wizard

Just started using yad and read smokey01's tutorial which is great. I did not see an example of how to capture the OKCancel button clicks.

Thanks
wizard


Re: YAD capture button click

Posted: Thu Dec 23, 2021 8:07 pm
by fredx181
wizard wrote: Thu Dec 23, 2021 7:43 pm

Just started using yad and read smokey01's tutorial which is great. I did not see an example of how to capture the OKCancel button clicks.

Thanks
wizard

Hi wizard, after the yad command;
[ $? -ne 0 ] && exit (exit if not equal to 0)
So will exit when clicking Cancel ($? is return value, in case of Cancel it will return value 1, so exit the script)
The OK button will return value 0, so then the script will continue.
EDIT: But if you mean how to capture a variable output from yad, that's another thing and possibly required that you share your code.


Re: YAD capture button click

Posted: Thu Dec 23, 2021 9:14 pm
by snoring_cat

Hi fredx181,

continuing on with what wizard said, there is another way to interact with buttons. You can run actions, such as call a function, when a button is clicked. However, wizard's methods of interaction are more commonly used.

As an FYI, I have made new YAD documentation in Notecase format. It is at https://github.com/w00fpack/YAD_Guides.


Re: YAD capture button click

Posted: Fri Dec 24, 2021 2:35 am
by wizard

@fredx181

When I run this in a script and click OK I get no echo message in the terminal. Something wrong?

Code: Select all

yad [ $? -ne 0 ] && exit
echo OK was clicked

Thanks
Wizard


Re: YAD capture button click

Posted: Fri Dec 24, 2021 4:41 am
by snoring_cat
wizard wrote: Fri Dec 24, 2021 2:35 am

Code: Select all

yad [ $? -ne 0 ] && exit
echo OK was clicked

Usually OK returns 0 and Cancel returns 1. Not sure why it reverses with your example. maybe yad and the [ ] sections are being evaluated instead of just [ ].

For your example, the code can be shortened to

Code: Select all

yad && exit
echo OK was clicked

This alternate example might be helpful if your buttons have different return codes

Code: Select all

yad
if [ $? -ne 0 ]; then
  exit
else
  echo OK was clicked
fi

Re: YAD capture button click

Posted: Fri Dec 24, 2021 5:34 am
by MochiMoppel
wizard wrote: Fri Dec 24, 2021 2:35 am

When I run this in a script and click OK I get no echo message in the terminal. Something wrong?

Code: Select all

yad [ $? -ne 0 ] && exit
echo OK was clicked

You need a ; after yad:

Code: Select all

yad ; [ $? -ne 0 ] && exit
snoring_cat wrote: Fri Dec 24, 2021 4:41 am

For your example, the code can be shortened to

Code: Select all

yad && exit
echo OK was clicked

Should be rather

Code: Select all

yad || exit
echo OK was clicked

Re: How to capture button click in YAD?

Posted: Fri Dec 24, 2021 1:46 pm
by wizard

@MochiMoppel

syntax, syntax, syntax, rules, rules, rules

drives me crazy, LOL

Merry Christmas

Thanks
wizard