Having trouble with Accessibility API of the ApplicationServices framework

After replacing Big Sur OSX 11.0 with the latest 11.5, my app's AXObserverAddNotification methods fails. Here is sample code I tested from StackOverflow: https://stackoverflow.com/questions/853833/how-can-my-app-detect-a-change-to-another-apps-window


AXUIElementRef app = AXUIElementCreateApplication(82695); // the pid for front-running Xcode 12.5.1

 CFTypeRef frontWindow = NULL;

 AXError err = AXUIElementCopyAttributeValue( app, kAXFocusedWindowAttribute, &frontWindow );

    if ( err != kAXErrorSuccess ){

        NSLog(@"failed with error: %i",err);

    }

NSLog(@"app: %@  frontWindow: %@",app,frontWindow);

'frontWindow' reference is never created and I get the error number -25204. It seems like the latest Big Sur 11.5 has revised the Accessibility API or perhaps there is some permission switch I am unaware of that would make things work. What am I doing wrong?

I too have the same problem on macOS Sequoia RC.

When I do it in C, it works. I wrote that parts of my app in C because of this problem; for a reason, AXObserverAddNotification() is always failing when I call it in Swift.

Having trouble with Accessibility API of the ApplicationServices framework
 
 
Q