Amethyst: Feature Request: Create new spaces with Amethyst

Created on 31 Mar 2014  Â·  7Comments  Â·  Source: ianyh/Amethyst

Sometimes I need to create a new space and throw windows into the new space. It would be useful (to me) to be able to handle this with Amethyst.

The best workflow I've found so far to add a new space:

  • use the Mission Control keyboard shortcut to show all spaces
  • hold down ⌥ (so the x's appear on each space as well as the large "plus sign" in the top-right corner of the display)
  • use a mouse to click the plus sign
  • then go back to a space and use Amethyst to manage the windows

I've attempted to use AppleScript and Accessibility Inspector, and also performed some cursory searches of Apple's Developer Docs and the Amethyst source to see if I could find a possible solution or related feature. But admittedly my beginner's skills fell short and I was unsuccessful :)

Is this possible? If so I'd be happy to continue my efforts with a nudge in the right direction -- even if it turns out I won't be able to use Amethyst to do this.

Trello Card

discussion needed enhancement

Most helpful comment

@codehearts When I run your script I get

> pbpaste | osascript
35:121: execution error: System Events got an error: sh: /Applications/Mission Control.app/Contents/MacOS/Mission Control: No such file or directory (127)

Replacing "/Applications/Mission\\ Control.app/Contents/MacOS/Mission\\ Control" with /System/Applications/Mission\\ Control.app/Contents/MacOS/Mission\\ Control" works for me on

> sw_vers -productVersion
10.15.2

All 7 comments

Hmm, I would have to dive deeper into Apple's API to see about this. The most brute force solution would be to handle it similarly to the way we handle moving windows to another space (which is to manipulate the mouse to click and drag the window while also using a hotkey to move to another space). This is rather inelegant, and I'm not sure how this would translate to different screen-sizes/set ups but one solution would be to do a similar thing.

i.e.

  • Trigger the mission control shortcut
  • Move the mouse and perform a mouse down event on the new space button.
  • Use a hotkey to move to the new space

There could also be a way to create a new space using the private API for spaces but if you were to take that route it wouldn't be merged into Amethyst because Ian does not wish to use any private APIs

@leonardt,

This answer from SO uses AppleScript and MouseTools to create a new space, however I'd also rather avoid unnecessary dependencies.

delay 0.5 -- time to release command if the script is run with command-R
tell application "System Events"
    key code 126 using control down -- control-up
    delay 1
    do shell script "MouseTools -x 1900 -y 60;sleep 1;MouseTools -leftClickNoRelease;MouseTools -releaseMouse"
    key code 53 -- escape
end tell

^ To get around the MouseTools and screen size dependencies I poked around in Accessibility Inspector and learned the button description for the plus sign is "add desktop," which appears unique, but I'm not sure how to tell AppleScript to find a button by that description after the spaces are displayed and the plus sign appears. Do you know how to do this?

Another answer from SO suggests modifying com.apple.spaces.plist to add a space and then restart the Finder process, but I think this might be too much of a hack. :)

Thoughts?

Something that is related to this is having the throw focused window to space shortcuts create a space before throwing if the requested space doesn't exist.

On Mojave I've been able to automate the creation of new spaces with this:

tell application "System Events"
  do shell script "/Applications/Mission\\ Control.app/Contents/MacOS/Mission\\ Control"
  click button 1 of group "Spaces Bar" of group 1 of group "Mission Control" of process "Dock"
  do shell script "/Applications/Mission\\ Control.app/Contents/MacOS/Mission\\ Control"
end tell

This approach also doesn't require a Mission Control keybinding to be set, but the windows do shrink for a split second as the animation starts and stops. Adding delay 0.5 after the click gives enough time for the animation to display the new space creation

@codehearts When I run your script I get

> pbpaste | osascript
35:121: execution error: System Events got an error: sh: /Applications/Mission Control.app/Contents/MacOS/Mission Control: No such file or directory (127)

Replacing "/Applications/Mission\\ Control.app/Contents/MacOS/Mission\\ Control" with /System/Applications/Mission\\ Control.app/Contents/MacOS/Mission\\ Control" works for me on

> sw_vers -productVersion
10.15.2

@codehearts script works for my mac version: 10.14.6
-- it might be nice to package this function to Amethyst; currently it's a pain point for me on mac (in comparison to using i3 on linux where things are all consistently done through keyboard)

The one and only two remaining features that will make amethyst 100% replace yabai for me is creating new spaces when I want to throw something (throw app from space 1 to space 7, itll create a second space instead of making 5 blank ones) and auto-destroying empty spaces when you move the last remaining app out of it

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kallekrantz picture kallekrantz  Â·  10Comments

paulrrogers picture paulrrogers  Â·  3Comments

tchapi picture tchapi  Â·  7Comments

timvisher picture timvisher  Â·  3Comments

airways picture airways  Â·  4Comments