zhuyuan-ice-gl-zy001/.tmp_axprobe/zyset.swift

14 lines
747 B
Swift
Raw Permalink Normal View History

2026-08-20 00:01:53 +08:00
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") }