Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Create new spaces with Amethyst #143

Open
charle5 opened this issue Mar 31, 2014 · 15 comments
Open

Feature Request: Create new spaces with Amethyst #143

charle5 opened this issue Mar 31, 2014 · 15 comments

Comments

@charle5
Copy link

charle5 commented Mar 31, 2014

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

@leonardt
Copy link
Contributor

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

@charle5
Copy link
Author

charle5 commented Apr 1, 2014

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

@syamajala
Copy link

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.

@codehearts
Copy link

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

@amckinlay
Copy link

amckinlay commented Feb 5, 2020

@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

@ipstone
Copy link

ipstone commented May 15, 2020

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

@rublev
Copy link

rublev commented Jun 1, 2020

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

@andresbrocco
Copy link

andresbrocco commented Mar 15, 2021

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

@clpatterson
Copy link

I'd also love this enhancement.

@Brin-o
Copy link

Brin-o commented Aug 16, 2021

I agree, having this would be amazing.

@prgres
Copy link

prgres commented Sep 6, 2021

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.

@pradeepb28
Copy link

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

@ianyh
Copy link
Owner

ianyh commented Jul 2, 2022

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

@OneHoopyFrood
Copy link

I'm on 12.5.

@codehearts solution with @amckinlay 's addition works

> sw_vers -productVersion
12.5

@VicSegers
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests