How to capture button click in YAD? SOLVED

interpretive language scripts


Moderator: Forum moderators

Post Reply
User avatar
wizard
Posts: 1969
Joined: Sun Aug 09, 2020 7:50 pm
Has thanked: 2620 times
Been thanked: 680 times

How to capture button click in YAD? SOLVED

Post 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

Last edited by wizard on Thu Dec 30, 2021 3:18 am, edited 1 time in total.

Big pile of OLD computers

User avatar
fredx181
Posts: 3043
Joined: Tue Dec 03, 2019 1:49 pm
Location: holland
Has thanked: 369 times
Been thanked: 1294 times
Contact:

Re: YAD capture button click

Post 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.

User avatar
snoring_cat
Posts: 206
Joined: Tue Sep 21, 2021 3:40 pm
Location: Earth
Has thanked: 24 times
Been thanked: 46 times

Re: YAD capture button click

Post 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.

Meeeooow!

-- substance over noise, since 5 minutes in the future --

User avatar
wizard
Posts: 1969
Joined: Sun Aug 09, 2020 7:50 pm
Has thanked: 2620 times
Been thanked: 680 times

Re: YAD capture button click

Post 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

Big pile of OLD computers

User avatar
snoring_cat
Posts: 206
Joined: Tue Sep 21, 2021 3:40 pm
Location: Earth
Has thanked: 24 times
Been thanked: 46 times

Re: YAD capture button click

Post 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

Meeeooow!

-- substance over noise, since 5 minutes in the future --

User avatar
MochiMoppel
Posts: 1229
Joined: Mon Jun 15, 2020 6:25 am
Location: Japan
Has thanked: 21 times
Been thanked: 436 times

Re: YAD capture button click

Post 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
User avatar
wizard
Posts: 1969
Joined: Sun Aug 09, 2020 7:50 pm
Has thanked: 2620 times
Been thanked: 680 times

Re: How to capture button click in YAD?

Post by wizard »

@MochiMoppel

syntax, syntax, syntax, rules, rules, rules

drives me crazy, LOL

Merry Christmas

Thanks
wizard

Big pile of OLD computers

Post Reply

Return to “Scripts”