You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
1.3 KiB
33 lines
1.3 KiB
import Cocoa
|
|
import ApplicationServices
|
|
|
|
func inspectFrontApp() {
|
|
guard let frontApp = NSWorkspace.shared.frontmostApplication else { return }
|
|
print("Frontmost App:", frontApp.localizedName ?? "")
|
|
|
|
let appElem = AXUIElementCreateApplication(frontApp.processIdentifier)
|
|
|
|
// 1. Try focused window
|
|
var windowObj: CFTypeRef?
|
|
var err = AXUIElementCopyAttributeValue(appElem, kAXFocusedWindowAttribute as CFString, &windowObj)
|
|
print("kAXFocusedWindowAttribute err:", err.rawValue)
|
|
|
|
if err == .success, let win = windowObj {
|
|
let winElem = win as! AXUIElement
|
|
var focusedObj: CFTypeRef?
|
|
let winErr = AXUIElementCopyAttributeValue(winElem, kAXFocusedUIElementAttribute as CFString, &focusedObj)
|
|
print("Window focused element err:", winErr.rawValue)
|
|
if winErr == .success, let elem = focusedObj {
|
|
let axElem = elem as! AXUIElement
|
|
var roleObj: CFTypeRef?
|
|
AXUIElementCopyAttributeValue(axElem, kAXRoleAttribute as CFString, &roleObj)
|
|
print("Role from window:", roleObj ?? "none")
|
|
|
|
var valObj: CFTypeRef?
|
|
AXUIElementCopyAttributeValue(axElem, kAXValueAttribute as CFString, &valObj)
|
|
print("Value from window:", valObj ?? "none")
|
|
}
|
|
}
|
|
}
|
|
|
|
inspectFrontApp()
|