如何在 Mac OS X Leopard 中检测用户所在的空间? [英] How to detect which Space the user is on in Mac OS X Leopard?

查看:26
本文介绍了如何在 Mac OS X Leopard 中检测用户所在的空间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Mac OS X Leopard 有一个名为 Spaces 的虚拟桌面实现.我想以编程方式检测用户当前所在的空间.

Mac OS X Leopard has a virtual desktop implementation called Spaces. I want to programatically detect which space the user is currently on.

Cocoa 更可取,但如果没有其他方法,AppleScript 是可以接受的.

Cocoa is preferable but AppleScript is acceptable if there's no other way.

我见过几个 AppleScript 实现,但是他们使用的技术在生产代码中使用似乎有点太hacky(一个依赖于引起错误然后解析错误消息以获取当前空间,另一个被询问空间菜单 GUI)

I've seen a couple of AppleScript implementations, but the techniques they used seemed a bit too hacky to use in production code (one relied on causing an error and then parsing the error message to get the current space, the other interrogated the Spaces menu GUI)

推荐答案

使用 HIWindowGetCGWindowID 获取 WindowRef 的 CGWindowID.

Use HIWindowGetCGWindowID to get the CGWindowID for your WindowRef.

将该 ID 与 CGWindow.h 中的 CGWindowListCreateDescriptionFromArray 一起使用以获取有关您的窗口的信息.

Use that ID with CGWindowListCreateDescriptionFromArray from CGWindow.h to get information on your window.

查看返回的字典并提取(可选)kCGWindowWorkspace 键.这是您的窗口的空间 ID.

Look at the returned dictionary and extract the (optional) kCGWindowWorkspace key. That is your space ID for your window.

这篇关于如何在 Mac OS X Leopard 中检测用户所在的空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆