I try to get all the application's windows.
fun main() = memScoped {
NSWorkspace.sharedWorkspace.runningApplications()
.map { it as NSRunningApplication }
.filter { it.active }
.forEach {
val applicationRef = AXUIElementCreateApplication(it.processIdentifier)
...
}
}
But i cant find the AXUIElement in kotlin native library but AXUIElementRef and AXUIElementRefVar. Many artical show the swift code to get AXUIElement, and i dont know how to change the code to kotlin.
The swift code like this:
if let pid = proToolsApp?.processIdentifier {
var result = [AXUIElement]()
var windowList: AnyObject? = nil // [AXUIElement]
let appRef = AXUIElementCreateApplication(pid)
if AXUIElementCopyAttributeValue(appRef, "AXWindows" as CFString, &windowList) == .success {
result = windowList as! [AXUIElement]
}
var docRef: AnyObject? = nil
if AXUIElementCopyAttributeValue(result.first!, "AXDocument" as CFString, &docRef) == .success {
let result = docRef as! AXUIElement
print("Found Document: \(result)")
let filePath = result as! String
print(filePath)
}
}