OSX狮子的AppleScript:如何从任务控制电流空间#? [英] OSX Lion AppleScript : How to get current space # from mission control?
问题描述
我想弄清楚如何获得任务控制当前空间#。来源将是有益的,但更多的帮助将是如何算出这个我自己的信息。我已经写了几个的AppleScript,但往往不是好像任何时候,我需要做一些新的东西(我找不到字典文件),它属于的类别下的讲这个特定应用(如系统活动),这很具体的事,我已经不知道我怎么会真正明白这一点。
I'm trying to figure out how to get the current space # from mission control. Source would be helpful, but more helpful would be info on how to figure this out myself. I've written a few applescripts, but more often than not it seems like any time I need to do something new (that I can't find dictionary documentation for) it falls under the category of "tell this specific app (e.g. "System Events") this very specific thing" and I've no clue how I would actually figure that out.
具体是什么,我试图做的:
Specifically what I am trying to do:
我的恨的新的使命在OSX 10.7控制。我希望我的空间回来,因为我用这一切的时候网格。我以前使用箭头键空间之间进行导航(例如<大骨节病> ALT 骨节病> + <大骨节病>↑骨节病>)每隔几秒钟。现在,我坚持与空间这个笨重的1X9阵列,而不是一个优雅的3x3的网格。我已经重新映射我的所有空间使用数字键盘,这部分需要照顾的问题(因为它是一个3x3网格),但只有当我有附加外接键盘。
I hate the new mission control in OSX 10.7. I want my spaces "grid" back since I used it all the time. I used to navigate between spaces using arrow keys (e.g. ALT+↑) every few seconds. Now I'm stuck with this clunky 1x9 array of spaces instead of an elegant 3x3 grid. I've re-mapped all my spaces to use the number pad, which partially takes care of the problem (since it is a 3x3 grid), but only when I have an external keyboard attached.
基本上,我希望能够使用<大骨节病> ALT 骨节病> + <大骨节病>↑骨节病>和<大骨节病>↓骨节病>了,但这样做,我需要检测当前空间#这样我可以从太空中5开关 - > 2,例如:
Basically, I want to be able to use ALT+↑ and ↓ again, but to do so I need to detect the current space # so that I can switch from space 5-->2, for example.
下面戴夫的回答,虽然远更详细的比我预想的,需要写一个应用程序来做到这一点(再加上它仍然不能完全回答这个问题)。如果这是在所有可能,我宁愿只是结合了一些关键的AppleScript。
Dave's answer below, although far more detailed than I expected, requires writing an app to do this (plus it still doesn't fully answer the question). If it's at all possible, I'd rather just bind a few keys to an applescript.
推荐答案
我想这出自己。现在还没有,但方向是正确的:
I'm trying to figure this out myself. Not there yet, but in the right direction:
- 每个任务控制中心的空间得到了
UUID
分配给它... - ...除了最前面的一个(据我所知),以及仪表板之一。
- Each Mission Control "space" gets a
uuid
assigned to it... - ...except for the very first one (AFAIK), and the Dashboard one.
您可以在这里阅读:
$ defaults read com.apple.spaces
$ defaults read com.apple.desktop
文件位置:
~/Library/Preferences/com.apple.spaces.plist
~/Library/Preferences/com.apple.desktop.plist
下面是我的。我已经启用了四个空格,和三个条目显示:
Here's mine. I have four spaces enabled, and three entries show up:
$ defaults read com.apple.spaces
{
spaces = (
{
type = 0;
uuid = "9F552977-3DB0-43E5-8753-E45AC4C61973";
},
{
type = 0;
uuid = "44C8072A-7DC9-4E83-94DD-BDEAF333C924";
},
{
type = 0;
uuid = "6FADBDFE-4CE8-4FC9-B535-40D7CC3C4C58";
}
);
}
如果您删除一个空格,该条目会从文件中删除。如果你添加一个空格,一个条目将被添加。再次,从未有桌面1或仪表板中的条目。
If you delete a space, that entry will get removed from the file. If you add a space, an entry will be added. Again, there's never an entry for Desktop 1 or Dashboard.
我不知道,如果有一个公共的API搞清楚 UUID
正显示在显示器上什么样的空间。我认为没有 UUID
表示显示1,和其他人的平均值显示1 + N
I'm not sure if there's a public API to figure out what space uuid
is being displayed on a display. I'd assume that no uuid
means Display 1, and the others' mean Display 1+n.
我参加了一个快速浏览通过的AppleScript编辑器库(窗口--->库),并没有看到在系统事件的任何条目空格
。这可能是一些可以用可可粉做的,可能是通过私有API,但我不知道有关AppleScript。
I took a quick glance through the AppleScript Editor Library (Window ---> Library) and didn't see any entries under System Events for spaces
. This is probably something that can be done with Cocoa, perhaps via private API, but I'm not sure about AppleScript.
更新 - 2011年7月23日
它看起来像船坞控制任务控制。你可以抓住它的头文件,像这样:
It looks like Dock controls Mission Control. You can grab its header files like so:
- 转至:
/系统/图书馆/ CoreServices / DOCK
- 右键点击和显示包内容
- 导航:
/内容/ MacOS的/
- 复制和
码头
粘贴二进制文件到你的桌面。 - 运行:
$类突降〜/桌面/ DOCK
- Go to:
/System/Library/CoreServices/Dock
- Right-Click and Show Package Contents
- Navigate:
/Contents/MacOS/
- Copy and paste the
Dock
binary to your desktop. - Run:
$class-dump ~/Desktop/Dock
这会吐出它的所有头文件(它的长,近7500行)。你可以看到 spaceUUID
字符串出现在那里。有一个名为 WVSpace
类这似乎重新present在任务控制一个空格,和许多其他WV *类的。
That'll spit out all of its header files (it's long; almost 7,500 lines). You can see the spaceUUID
strings appearing in there. There's a class called WVSpace
which appears to represent a single Space in Mission Control, and a lot of other WV* classes.
我会一直看着它明天;现在太累了。 :)
I'll keep looking at it tomorrow; too tired now. :)
更新 - 2011年7月24日
在Dock中,有一个名为类 WVSpaces
。它有许多属性,包括:
Inside Dock there's a class called WVSpaces
. It has a number of attributes including:
WVSpace *currentSpace;
unsigned int currentWorkspace;
WVSpace *nextSpace; // Space on the right???
WVSpace *previousSpace; // Space on the left???
BOOL currentSpaceIsDashboard;
BOOL dashboardIsCurrent;
...lots more...
每个 WVSpace
类有一个的NSString * _uuid;
属性,这可能是其SpaceUUID。所以理论上你可以得到当前空间数,像这样:
Each WVSpace
class has an NSString *_uuid;
attribute, which is likely its SpaceUUID. So theoretically you can get the current space number like so:
WVSpace *currentSpace = [[WVSpaces sharedInstance] currentSpace];
NSString *currentSpaceUUID = [currentSpace _uuid]; // Empty string if main space???
的诀窍是,如何让获得埋藏船坞内的私人 WVSpaces
类?我假设它是单身,因为它有一个的NSMutableArray * _spaces;
属性,可能是在它上市的每一个空间。只有一个空间得到一次显示(这一点,如果你使用多个显示器也是如此;在这两个他们的空间跨度),因此是很有意义的只能有一个 WVSpaces
实例。
The trick is, how to get access to the private WVSpaces
class buried inside of Dock? I'm assuming it's Singleton as it has an NSMutableArray *_spaces;
attribute, probably with every space listed in it. Only one space gets displayed at a time (this holds true if you're using multiple monitors; the space spans across both of them), so it makes sense to only have one WVSpaces
instance.
所以看起来它会要求码头的一些 SIMBL 黑客获得对<$访问C $ C> WVSpaces 。
So it looks like it'll require some SIMBL hacking of Dock to gain access to WVSpaces
.
这篇关于OSX狮子的AppleScript:如何从任务控制电流空间#?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!