I want to use the Accessibility API to get a list of all windows for a given application (external).
The goal is to check if a certain window is open. First I chec
This works for me in Swift 5.1:
let windowList: CFArray? = CGWindowListCopyWindowInfo(.optionOnScreenOnly, kCGNullWindowID)
for entry in windowList! as Array {
let ownerName: String = entry.object(forKey: kCGWindowName) as? String ?? "N/A"
let ownerPID: Int = entry.object(forKey: kCGWindowOwnerPID) as? Int ?? 0
print("ownerName: \(ownerName), ownerPID:\(ownerPID)")
}