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

查看:207
本文介绍了如何检测用户在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实现,但是他们使用的技术似乎有点太黑了,不能使用生产代码(一个依赖于导致错误,然后解析错误消息以获取当前空间,另一个查询空间菜单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.

使用CGWindowListCreateDescriptionFromArray从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天全站免登陆