I'm trying to access the windows of running applications through my application. Currently, I am grabbing the data of all running applications, and the kCGWindowNumber mapped to the applications, but I am having trouble getting the window mapped to that kCGwindowNumber.
How can I reference my windows of other running applications through mine? I have the kCGWindowNumber of those applications, but cannot figure out how to get access to the windows.
This is how I grab my data
let options = CGWindowListOption(arrayLiteral: CGWindowListOption.excludeDesktopElements, CGWindowListOption.optionOnScreenOnly)
let windowListInfo = CGWindowListCopyWindowInfo(options, CGWindowID(0))
Then, I store it into an object, which represents my running application. E.g.
{
kCGWindowAlpha = 1;
kCGWindowBounds = {
Height = 22;
Width = 3840;
X = 5520;
Y = 0;
};
kCGWindowLayer = 24;
kCGWindowMemoryUsage = 341416;
kCGWindowNumber = 190;
kCGWindowOwnerName = "Google Chrome";
kCGWindowOwnerPID = 272;
kCGWindowSharingState = 1;
kCGWindowStoreType = 2;
}
Now that I have the kCGWindowNumber I was trying to access the other applications with this
NSApplication.shared.window(withWindowNumber: kCGWindowNumber_FOR_WINDOW_I_WANT)
but, after reading the documentation I realized that NSApplication.shared returns Returns the application instance, and these windows are not not apart of my application.