我正在开发一个可与应用程序窗口一起使用的 macOS 应用程序。我现在无法承担的目标是检索所有打开的应用程序窗口的列表,它看起来像这样(JSON 示例):
[
{
"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
}
]
}
]
Run Code Online (Sandbox Code Playgroud)
每个应用程序都有一系列打开的窗口以及打开它的桌面号码。全尺寸应用程序占用单独的桌面空间,因此它应该有一个单独的桌面编号。
我知道如何使用 获取打开的窗口列表CGWindowListCopyWindowInfo,但我找不到找到桌面号码或确定哪个窗口可见或不可见的方法。
如果不可能用 Swift …