17 lines
775 B
Swift
Executable file
17 lines
775 B
Swift
Executable file
import Cocoa
|
|
let px = Float(CommandLine.arguments[1])!, py = Float(CommandLine.arguments[2])!
|
|
let sw = AXUIElementCreateSystemWide()
|
|
var el: AXUIElement?
|
|
let r = AXUIElementCopyElementAtPosition(sw, px, py, &el)
|
|
print("hitResult=\(r.rawValue)")
|
|
if let el {
|
|
func attr(_ e: AXUIElement, _ a: String) -> String {
|
|
var v: CFTypeRef?
|
|
guard AXUIElementCopyAttributeValue(e, a as CFString, &v) == .success else { return "?" }
|
|
return "\(v!)"
|
|
}
|
|
print("role=\(attr(el, kAXRoleAttribute)) title=\(attr(el, kAXTitleAttribute)) desc=\(attr(el, kAXDescriptionAttribute))")
|
|
var pid: pid_t = 0; AXUIElementGetPid(el, &pid)
|
|
let owner = NSRunningApplication(processIdentifier: pid)?.localizedName ?? "?"
|
|
print("ownerPid=\(pid) owner=\(owner)")
|
|
}
|