I am using Core Graphics to read window titles from other processes.
@objc public func getWindowDetailsByPid(_ pid: pid_t) -> NSDictionary? {
guard let windowList = CGWindowListCopyWindowInfo([.optionOnScreenOnly], kCGNullWindowID) as NSArray? else { return nil }
for case let window as NSDictionary in windowList {
if let windowPID = window[kCGWindowOwnerPID as String] as? Int, windowPID == pid {
let windowTitle = window[kCGWindowName as String] as? String ?? ""
if let windowNumber = window[kCGWindowNumber as String] as? NSNumber {
let windowId = windowNumber.uint32Value
let windowOwnerName = window[kCGWindowOwnerName as String] as? String ?? ""
return ["windowOwner":windowOwnerName, "windowTitle": windowTitle, "windowId": windowId]
}
}
}
return nil
}
}
This works as long as the window is not minimized, since I have selected the optionOnScreenOnly. However, I also want to read the window titles of minimized windows, so I selected optionAll. Now, I am getting the information of all windows but no window titles at all, whether onscreen or minimized.
Is there a way to read the window titles of minimized windows?
I know it works with MacOS's Accessibility API, but the problem there is that there is no way to get the window ID and I absolutely need the window ID to be able to assign window titles to a specific ID.
Why optionAll doesn't work and is there a other way to get the window titles and IDs of minimized windows?