C class name corresponding to an AXUIElement?

Apple's Accessibility Inspector tool displays the Objective-C class corresponding to the currently inspected UI Element. See NSButtonCell at the very bottom of this screenshot:

辅助功能检查器屏幕截图

However, how can I extract this information in my own code? The accessibility methods in Apple's seven year old UIElementInspector sample code do not surface the element's class name.

Reverse engineering the Accessibility Inspector hinted that the Objective-C class name could be obtained via the AXClassName attribute, but that attribute is always nil for me.


AppKit limits access to the AXClassName attribute, and several other attributes, to applications that have the com.apple.private.accessibility.inspection entitlement. The XPC service that Accessibility Inspector uses to access accessibility information has this entitlement. Since this is a private entitlement, I believe it can only be added to applications signed by an Apple certificate.

You can confirm for yourself that the entitlement is key by stripping entitlements from the Accessibility Inspector's XPC service like so (make a back-up of Accessibility Inspector first!):

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

If you then open Accessibility Inspector you'll see that most all of the functionality works correctly, except for things like the class name that are gated on the private entitlements.

Accessibility Inspector with entitled XPC service

Accessibility Inspector with unentitled XPC service

链接地址: http://www.djcxy.com/p/40132.html

上一篇: 无法使es6与Gulp一起工作

下一篇: 与AXUIElement对应的C类名称?