AXSwift icon indicating copy to clipboard operation
AXSwift copied to clipboard

Focus required for interactions

Open nameghino opened this issue 3 years ago • 4 comments

I'm trying to build a sort of POC for a software remote controller to Keynote to pass slides and I found that whenever I click on my application's UI to trigger a Keynote change, nothing happens unless Keynote is in foreground, so I have to resort to cmd+clicking on my app so that Keynote remains foreground and then the AXPress event is sent and received by Keynote

I've tried using AXRaise to bring Keynote to front before sending the AXPress event but I find that it's still not received.

Is there something I'm doing wrong? How can I use AXSwift to bring Keynote to front so that my events are delivered?

Thanks!

nameghino avatar Dec 19 '22 19:12 nameghino

Try to AXRaise the parent window of the element that you want to perform an action on.

soundflix avatar Dec 19 '22 19:12 soundflix

I tried sending AXRaise to both the Application object and to all its top level windows, still doesn't work. However, I got it to work by using the NSWorkspace APIs and then calling activate(withOptions:) on the target app.

nameghino avatar Dec 20 '22 14:12 nameghino

What do you mean with "top-level windows"? A window is always first level above Application. And you have to raise the window that contains your target element, not all. But some apps just don't behave so well with Accessibility.

soundflix avatar Dec 20 '22 16:12 soundflix

Some (not all) AX Objects for buttons and the like will have an attribute ".focused". Check if the ".focused" attribute is there and then set it to "true". Once you set this, then try your .performAction(.press). I found this was a requirement from Big Sur and later for some AX Objects. Use the Accessibility Inspector and see if an attribute "Keyboard Focused" is there and if it is set-able.

DavidMolnar-RS avatar Jan 11 '23 23:01 DavidMolnar-RS