How to Click on a Button in an App

I am trying to activate Cicso AnyConnect VPN by assigning a hotkey and trying to press Connect.

Here are my settings

Tried with simulating a Tab and Return hoping that the focus is on Connect (which works if I do it manually) and pressing a button Connect

Also, tried to use Window Analysis tool for System Events to see which button is pressed (but for some reason can't activate it when I am on OpenConnect)

So if anyone can answer both questions

  • how to simulate pressing Connect
  • how to use Window Analysis tool so that I can fish nextime

Best Regards
Kailash

1 Like

Hi, this might be a button pressing solution for you:

For things like this where other options aren't working I usually fall back on GUI AppleScripting. UI Browser will give you the element's information which you can use to have System Events click on it.

I don't know if you've solved your problem or if my suggestion will help your situation, but when I look at your code I see some risky assumptions that you are making. I run into situations similar to yours all the time, with programs that behave oddly, and here's how I would try to address the problem. Instead of running the action to press the button as you do, I would first write code to wait until the button appears, and then press (repeatedly, with a short pause for safety) until it disappears. Something like this:

image

This approach is a safer way to press a button, but it doesn't even take into account some situations like handling timeouts. So when I write code as simple as pressing a button, and I want to do it reliably, sometimes the code to press the button can be a full page in size.

In the future I plan to use subroutines to press buttons like this. My subroutine would probably look something like this:

image

The error message could perhaps be sent as an SMS message to my Apple Watch, if I wanted to see my error handling messages when I'm away from home.

I didn't upload this code because I didn't test it, and because it's too trivial to upload.

That most likely means you haven't given the macro a global scope, but some of these apps are tricky in how they present themselves...

-Chris

I don't have that VPN so don't know how it works but does it not work to tab to the Connect button and press the spacebar to activate it? A lot of apps work that way.

Looks like UI Browser is end of life and going away :slightly_frowning_face:

I came to this forum specifically to do this exact thing lol. Thank you.

1 Like

Welcome! I'm glad you found this forum and this topic in particular.

If you stick around you'll find that this is a very friendly and helpful community. :grin:

-Chris

2 Likes