How can I move a window to a target space with App

2019-06-22 12:46发布

问题:

Ultimately I'm trying to assign hotkeys (via Alfred or Keymando) that can move the frontmost application to any of my spaces. Triggering an applescript seems the most likely route to success. I've looked around a lot and it seems there used to be a way to do this via "spaces preferences" in applescript, but this disappeared in OS X Lion.

回答1:

If you’re after a pure AppleScript solution you’re out of luck.

As you mentioned the Spaces preference pane is gone. In addition, Mission Control.app has no dictionary to open, and pulling a window’s properties (tell application Finder to set x to the front finder window's properties) doesn't show anything that relates to Spaces.

System Events’s dictionary has a current desktop property that I can’t wrangle, and in any case is listed as read only.

However, each space after the first and the dashboard has a UUID that is contained in a .plist file (com.apple.spaces) that you can find in ~/Library/Preferences. In that .plist there is also an "app-bindings" section, which suggests that the behaviour you used to be able to access through the Exposé/Spaces preference pane is not totally gone.

Unfortunately in my testing, where I added a dict & string pair to "app-bindings", I couldn’t force an application to a particular space, even after a restart.

It appears that when Apple ditched the Spaces grid for Mountain Lion’s Mission Control row they threw away user control over what was to appear in each space, and by the way the interaction has changed (ad-hoc extra desktops compared with a user-defined grid) I wouldn’t be surprised if things have changed under the covers too.