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

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

问题描述

的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的哪些空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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