I'm developing a macOS app that would work with app windows. The goal which I couldn't now afford is to retrieve a list of all opened app windows, which would look something like that (JSON example):
[
{
"appName": "Google Chrome",
"appWindows": [
{
"size": {"x": 100, "y": 100},
"position": {"height": 100, "width": 100},
"desktopNumber": 2
},
{
"size": {"x": 100, "y": 100},
"position": {"height": 100, "width": 100},
"desktopNumber": 3
}
]
},
{
"appName": "Telegram",
"appWindows": [
{
// full screen app, so has a separate desktop number
"size": {"x": 1080, "y": 1920},
"position": {"height": 0, "width": 0},
"desktopNumber": 4
}
]
}
]
Each app has an array of opened windows alongside a desktop number where it's been opened. A full-size app took a separate desktop space, so it should have a separate desktop number.
I know how to get an opened window list with CGWindowListCopyWindowInfo, but I couldn't find a way to find a desktop number or determine which window is visible or not.
If it's not possible to do with Swift, then perhaps there are apple script solutions?