Amethyst icon indicating copy to clipboard operation
Amethyst copied to clipboard

Feature Request: Create new spaces with Amethyst

Open charle5 opened this issue 10 years ago • 14 comments

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

charle5 avatar Mar 31 '14 04:03 charle5

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 avatar Mar 31 '14 17:03 leonardt

@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?

charle5 avatar Apr 01 '14 02:04 charle5

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.

syamajala avatar Sep 15 '15 15:09 syamajala

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 avatar Sep 06 '19 20:09 codehearts

@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

amckinlay avatar Feb 05 '20 10:02 amckinlay

@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)

ipstone avatar May 15 '20 16:05 ipstone

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

rublev avatar Jun 01 '20 23:06 rublev

Any advancements on this enhancement?! I would love this feature

andresbrocco avatar Mar 15 '21 23:03 andresbrocco

I'd also love this enhancement.

clpatterson avatar Apr 01 '21 14:04 clpatterson

I agree, having this would be amazing.

Brin-o avatar Aug 16 '21 13:08 Brin-o

I'm trying to work around it with AppleScripts but would love to get rid off a dependency like that and see this feature in Amethyst.

prgres avatar Sep 06 '21 07:09 prgres

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 I wonder if it is possible to do something like this After the new space is created, is it possible to switch to that new space programmatically ?

Thanks :)

pradeepb28 avatar Jun 25 '22 04:06 pradeepb28

I think I'm convinced that Amethyst should have this.

ianyh avatar Jul 02 '22 03:07 ianyh

I'm on 12.5.

@codehearts solution with @amckinlay 's addition works

> sw_vers -productVersion
12.5

OneHoopyFrood avatar Sep 21 '22 15:09 OneHoopyFrood

I am trying to enhance the previously created solution by @codehearts with the addition of @amckinlay (which btw works on my current version 12.6) by adding the ability to handle multiple monitors. I found out that the group 1 in line

click button 1 of group "Spaces Bar" of group 1 of group "Mission Control" of process "Dock"

refers to the first monitor. But I am struggling to get the number of the currently active monitor through Applescript, but I am really inexperienced with the language.

I tried understanding the answer of this question, but couldn't manage to get something working with it.

VicSegers avatar Nov 23 '22 03:11 VicSegers