14 lines
747 B
Swift
14 lines
747 B
Swift
import Cocoa
|
||
let pid = pid_t(CommandLine.arguments[1])!
|
||
let app = AXUIElementCreateApplication(pid)
|
||
var focused: CFTypeRef?
|
||
AXUIElementCopyAttributeValue(app, kAXFocusedUIElementAttribute as CFString, &focused)
|
||
if let f = focused {
|
||
var r1: CFTypeRef?
|
||
AXUIElementCopyAttributeValue(f as! AXUIElement, kAXRoleAttribute as CFString, &r1)
|
||
print("focused role: \(r1 as? String ?? "?")")
|
||
let setR = AXUIElementSetAttributeValue(f as! AXUIElement, kAXValueAttribute as CFString, "ZYSET-PROBE" as CFTypeRef)
|
||
print("set value result: \(setR.rawValue) (0=success)")
|
||
// 立即清空,不留痕
|
||
AXUIElementSetAttributeValue(f as! AXUIElement, kAXValueAttribute as CFString, "" as CFTypeRef)
|
||
} else { print("no focused element") }
|