How to get the Objective-C class name corresponding to AXUIElement?

The Apple Accessibility Inspector tool renders the Objective-C class that corresponds to the currently validated user interface element. See NSButtonCell at the very end of this screenshot:

Screenshot Accessibility Inspector

However, how can I extract this information into my own code? Availability methods in the Apple UIElementInspector Seven-Year Code Example do not display the element's class name.

The reverse engineering of the accessibility inspector hinted that the Objective-C class name can be obtained using the AXClassName attribute, but this attribute is always zero.

+7
objective-c accessibility appkit accessibility-api macos
source share
1 answer

AppKit restricts access to the AXClassName attribute and several other attributes to applications eligible for com.apple.private.accessibility.inspection . The XPC service that the Accessibility Inspector uses to access availability information has this right. Since this is a personal right, I believe that it can only be added to applications signed with an Apple certificate.

You yourself can verify that the right is key by removing rights from the XPC Accessibility Inspector in this way (first back up the accessibility inspector!):

 codesign -f -s - /Applications/Xcode.app/Contents/Applications/Accessibility\ Inspector.app/Contents/Frameworks/AccessibilityAuditDeviceManager.framework/XPCServices/axAuditService.xpc 

If you then open the Accessibility Inspector, you will see that most functions work correctly, with the exception of things like the class name, which is private.

XPC-enabled Availability Inspector

wBuHE.png

XPC Perpetual Availability Inspector

6RR3a.png

+3
source share

All Articles