zhuyuan-ice-gl-zy001/.tmp_axprobe/zyset.swift
2026-08-20 00:01:53 +08:00

14 lines
747 B
Swift
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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") }