问题描述
的Mac OS X Leopard中有一个名为虚拟桌面实现。我想编程检测用户当前在其空间
Mac OS X Leopard has a virtual desktop implementation called Spaces. I want to programatically detect which space the user is currently on.
可可preferable ,但的AppleScript是可以接受如果没有其他办法。
Cocoa is preferable but AppleScript is acceptable if there's no other way.
我见过一对夫妇的AppleScript实现,但他们所使用的技术似乎有点太哈克生产code使用(一个依赖导致错误,然后解析错误消息以获取当前的空间,其他审问空间菜单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得到CGWindowID您WindowRef。
Use HIWindowGetCGWindowID to get the CGWindowID for your WindowRef.
使用与CGWindowListCreateDescriptionFromArray该ID从CGWindow.h让你的窗口的信息。
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的哪些空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!