23 lines
967 B
Swift
Executable file
23 lines
967 B
Swift
Executable file
import Cocoa
|
|
let pid = pid_t(CommandLine.arguments[1])!
|
|
let app = AXUIElementCreateApplication(pid)
|
|
var wRef: CFTypeRef?
|
|
AXUIElementCopyAttributeValue(app, kAXFocusedWindowAttribute as CFString, &wRef)
|
|
func findWeb(_ e: AXUIElement, _ depth: Int) {
|
|
if depth > 12 { return }
|
|
var r: CFTypeRef?
|
|
AXUIElementCopyAttributeValue(e, kAXRoleAttribute as CFString, &r)
|
|
if (r as? String) == "AXWebArea" {
|
|
var u: CFTypeRef?
|
|
AXUIElementCopyAttributeValue(e, "AXURL" as CFString, &u)
|
|
var t: CFTypeRef?
|
|
AXUIElementCopyAttributeValue(e, kAXTitleAttribute as CFString, &t)
|
|
print("WebArea title=\(String(describing: t)) url=\(String(describing: u))")
|
|
return
|
|
}
|
|
var kids: CFTypeRef?
|
|
if AXUIElementCopyAttributeValue(e, kAXChildrenAttribute as CFString, &kids) == .success, let arr = kids as? [AXUIElement] {
|
|
for k in arr { findWeb(k, depth+1) }
|
|
}
|
|
}
|
|
if let w = wRef { findWeb(w as! AXUIElement, 0) }
|