Swift:获取带有桌面号码和位置信息的打开应用窗口列表
我正在开发一个可以与应用Windows一起使用的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
}
]
}
]
每个应用程序都有一系列打开的窗口,并在桌面号码旁边打开。一个全尺寸的应用程序包含一个单独的桌面空间,因此它应该具有单独的桌面号码。
我知道如何使用cgwindowlistcopywindowinfo
获得打开的窗口列表,但是我找不到找到桌面号码的方法或确定哪个窗口可见。
如果不可能与Swift一起做,那么也许有Apple脚本解决方案?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以检索应用程序名称,边界&使用以下代码显示显示:
示例输出:
使用此代码创建
JSON
对象是微不足道的。顺便说一句,您可能需要更改:要
注意,没有UI的应用程序可能没有
display
值。You can retrieve app names, bounds & displays using following code:
Example output:
Creating the
JSON
object with this code is trivial. Btw, you may want to change:to
Also, note that apps without a UI may not have a
Display
value.