OSX Lion AppleScript:如何从任务控制中获取当前空间#? [英] OSX Lion AppleScript : How to get current space # from mission control?

查看:18
本文介绍了OSX Lion 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.

特别是我想要做的:

讨厌 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.

下面 Dave 的回答,虽然比我预期的要详细得多,但需要编写一个应用程序来做到这一点(而且它仍然没有完全回答这个问题).如果可能的话,我宁愿将几个键绑定到一个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...
  • ...除了第一个 (AFAIK) 和仪表板.

您可以在这里阅读:

$ 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";
        }
    );
}

如果您删除一个空格,该条目将从文件中删除.如果添加空格,则会添加一个条目.同样,Desktop 1 或 Dashboard 永远没有条目.

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 意味着 Display 1,而其他人的意思是 Display 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 编辑器库(窗口 ---> 库),没有看到 spaces 的系统事件下的任何条目.这可能可以通过 Cocoa 来完成,也许是通过私有 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 日

它看起来像 Dock 控制任务控制.你可以像这样获取它的头文件:

It looks like Dock controls Mission Control. You can grab its header files like so:

  1. 转到:/System/Library/CoreServices/Dock
  2. 右键单击并显示包内容
  3. 导航:/Contents/MacOS/
  4. Dock 二进制文件复制并粘贴到您的桌面.
  5. 运行:$class-dump ~/Desktop/Dock
  1. Go to: /System/Library/CoreServices/Dock
  2. Right-Click and Show Package Contents
  3. Navigate: /Contents/MacOS/
  4. Copy and paste the Dock binary to your desktop.
  5. Run: $class-dump ~/Desktop/Dock

这会吐出它的所有头文件(它很长;将近 7,500 行).您可以看到 spaceUUID 字符串出现在那里.有一个名为 WVSpace 的类,它似乎代表 Mission Control 中的单个 Space,以及许多其他 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???

诀窍是,如何访问隐藏在 Dock 中的私有 WVSpaces 类?我假设它是 Singleton,因为它有一个 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.

所以看起来它需要对 Dock 进行一些SIMBL hacking获得对 WVSpaces 的访问权.

So it looks like it'll require some SIMBL hacking of Dock to gain access to WVSpaces.

这篇关于OSX Lion AppleScript:如何从任务控制中获取当前空间#?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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