gpt4 book ai didi

objective-c - 如何获得 NSAccessibility child

转载 作者:行者123 更新时间:2023-12-03 17:11:01 30 4
gpt4 key购买 nike

我正在尝试使用 NSAccessibilityChildrenAttribute 获取 AXUIElement 的子级数组,以便构建所有 AXUIElement 的树一个应用程序。

它在 Mac native 应用程序上运行良好,但在 Java 应用程序(如 NetBeans)上运行不佳。

当我获得带有 AXUIElementCopyElementAtPosition (AXUIElementRef application, float x,float y, AXUIElementRef *element)AXUIElement 时,我可以通过返回到root,但我无法获取 child 。

还有其他方法可以访问 child 吗?

最佳答案

import Foundation
import AppKit
import ApplicationServices

let indd = NSWorkspace.shared.runningApplications.filter{$0.bundleIdentifier == "com.adobe.InDesign"}.first!
indd.activate(options: .activateIgnoringOtherApps)
let app = AXUIElementCreateApplication(indd.processIdentifier)
var attArray:CFArray?
AXUIElementCopyAttributeNames(app, &attArray)
print(attArray ?? "nil")
var childrenPtr:CFTypeRef?
AXUIElementCopyAttributeValue(app, kAXChildrenAttribute as CFString, &childrenPtr)
let children = childrenPtr as! CFArray
print(children)

CFArray 包含父应用程序的子应用程序。同样的原理可以递归地重复。

上面的代码在 Obj-C 中看起来应该类似。我从工作区复制粘贴了此内容。

您问题的关键答案是

AXUIElementCopyAttributeValue(app, kAXChildrenAttribute as CFString, &childrenPtr)

由于子级在此模型中是父级的属性。

关于objective-c - 如何获得 NSAccessibility child ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28452264/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com