小编Lic*_*ich的帖子

Swift:获取打开的应用程序窗口列表,其中包含桌面编号和位置信息

我正在开发一个可与应用程序窗口一起使用的 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 …

macos applescript desktop-application swift

2
推荐指数
1
解决办法
1342
查看次数

标签 统计

applescript ×1

desktop-application ×1

macos ×1

swift ×1