OSX Lion AppleScript : How to get current space # from mission control?

前端 未结 7 1115
悲&欢浪女
悲&欢浪女 2020-12-07 11:09

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\

7条回答
  •  星月不相逢
    2020-12-07 11:52

    ... also been working on this :)

    You say that you "need to to detect the current space #". This is not strictly true: To move down one row, you just move 3 spaces right, so in principle you could just bind something like

    tell application "System Events" to tell process "WindowServer"
        key code {124, 124, 124} using control down
    end tell
    

    to Alt-down (with FastScripts, Alfred or some other fast method that avoids the overhead of Automator). This approach will fail if you ever hit down in the bottom row, of course -- but if you are truly hard-wired, you never do :)
    You have to "Enable access for assistive devices" in the Universal Access preference pane for the key code approach to work.

    Caveat: This doesn't work. When I launch the script above, I nicely jump three spaces. The problem is that afterwards my keyboard goes unresponsive: It seems that only the window manager is receiving events: I can close windows and switch space, but I cannot interact with any applications.
    My theory is that this happens when the jump causes the current application to change during the execution of the script -- but I have no idea how to fix this.

    A related observation: The Mission Control (i.e. /Applications/Mission Control.app/Contents/MacOS/Mission\ Control) seems to react to some command line arguments:

    • Mission\ Control: show mission control
    • Mission\ Control 1: show desktop
    • Mission\ Control 2: show current application windows

    I tried putting in some of the UUID's from defaults read com.apple.spaces, but that didn't do much. So much for fumbling in the dark.

提交回复
热议问题