Sorry for not checking back sooner.
Here’s a function that returns more manageable data:
ObjC.import('CoreGraphics');
Ref.prototype.$ = function() {
return ObjC.deepUnwrap(ObjC.castRefToObject(this));
}
Application.prototype.getWindowList = function() {
let pids = Application('com.apple.systemevents')
.processes.whose({ 'bundleIdentifier':
this.id() }).unixId();
return $.CGWindowListCopyWindowInfo(
$.kCGWindowListExcludeDesktopElements,
$.kCGNullWindowID).$()
.filter(x => pids.indexOf(x.kCGWindowOwnerPID) + 1
&& x.kCGWindowLayer == 0
&& x.kCGWindowStoreType == 1
&& x.kCGWindowAlpha == 1
).map(x => [{ id : x.kCGWindowNumber,
name : x.kCGWindowName,
bounds : x.kCGWindowBounds
}]);
}
To use, e.g. to get Terminal’s windows:
Application('Terminal').getWindowList();