31 lines
1.6 KiB
Swift
Executable file
31 lines
1.6 KiB
Swift
Executable file
import Cocoa
|
|
// move mouse to (849,707) global logical, no click
|
|
let move = CGEvent(mouseEventSource: nil, mouseType: .mouseMoved, mouseCursorPosition: CGPoint(x: 849, y: 707), mouseButton: .left)
|
|
move?.post(tap: .cghidEventTap)
|
|
usleep(400_000)
|
|
// query AX element at that point for pid 1668
|
|
let app = AXUIElementCreateApplication(1668)
|
|
var el: AXUIElement?
|
|
let err = AXUIElementCopyElementAtPosition(app, 849, 707, &el)
|
|
print("AXUIElementCopyElementAtPosition err=\(err.rawValue)")
|
|
if let el = el {
|
|
func s(_ a: String) -> String {
|
|
var v: CFTypeRef?
|
|
if AXUIElementCopyAttributeValue(el, a as CFString, &v) == .success, let st = v as? String { return st.replacingOccurrences(of: "\n", with: "⏎") }
|
|
return ""
|
|
}
|
|
print("role=\(s(kAXRoleAttribute)) title=\(s(kAXTitleAttribute)) value=\(String(s(kAXValueAttribute).prefix(80))) desc=\(s(kAXDescriptionAttribute)) url=\(s(kAXURLAttribute))")
|
|
// walk up parents a few levels
|
|
var cur = el
|
|
for _ in 0..<5 {
|
|
var p: CFTypeRef?
|
|
guard AXUIElementCopyAttributeValue(cur, kAXParentAttribute as CFString, &p) == .success, let pp = p else { break }
|
|
cur = pp as! AXUIElement
|
|
var v: CFTypeRef?
|
|
var role = "", val = ""
|
|
if AXUIElementCopyAttributeValue(cur, kAXRoleAttribute as CFString, &v) == .success { role = (v as? String) ?? "" }
|
|
v = nil
|
|
if AXUIElementCopyAttributeValue(cur, kAXValueAttribute as CFString, &v) == .success { val = String(((v as? String) ?? "").prefix(50)).replacingOccurrences(of: "\n", with: "⏎") }
|
|
print(" parent role=\(role) val=\(val)")
|
|
}
|
|
}
|