【发布时间】:2021-10-30 07:17:50
【问题描述】:
如何将此 AppleScript 代码翻译成 Swift ?
tell application "System Events" to tell process "Safari" to get UI elements of first window
我已经到达“Safari”的第一个窗口,但我不知道如何获取 UI 元素
let pid = NSWorkspace.shared.runningApplications.first(where: {$0.localizedName == "Safari"})?.processIdentifier
let appRef = AXUIElementCreateApplication(pid!)
var windows: AnyObject?
_ = AXUIElementCopyAttributeValue(appRef, kAXWindowsAttribute as CFString, &windows)
if let firstWindow = (windows as? [AXUIElement])?.first{
print(firstWindow)
}
【问题讨论】:
标签: swift cocoa applescript