1

I am aware you can do it from Mission Control by clicking and there is no shortcut available in 'Keyboard'.

Are there any ways to do this by using a 3rd party program or Shell/ Applescript?

The solution presented here only doesn't work in Big Sur anymore.

1

Tested under macOS Big Sur and macOS Catalina using English (US) as the language, the following example AppleScript code works to programmatically add another Desktop:

do shell script "open -a 'Mission Control'"
delay 0.5
tell application "System Events" to ¬
    click (every button whose value of ¬
        attribute "AXDescription" is "add desktop") of ¬
        group 2 of group 1 of group 1 of process "Dock"
delay 0.5
tell application "System Events" to key code 53

Note that most likely works from macOS Sierra onwards. Prior to that, remove group 2 of group 1 of from the code.


For other languages, including English, try the following example AppleScript code:

do shell script "open -b 'com.apple.exposelauncher'"
delay 0.5
tell application id "com.apple.systemevents"
    tell (every application process ¬
        whose bundle identifier = "com.apple.dock") to ¬
        click (button 1 of group 2 of group 1 of group 1)
    delay 0.5
    key code 53 -- esc key
end tell
5
  • This only opens and closes Mission control for me. Maybe it has something to do with my language being German? When I use this code: tell application "System Events" tell application "Mission Control" to launch tell group 2 of group 1 of group 1 of process "Dock" click (every button whose value of attribute "AXDescription" is "add desktop") end tell end tell it returns "missing value"
    – Fyn
    Nov 27 '20 at 16:26
  • My intuition was right, I switched my language to English (GB) and now it WORKED. Thanks for letting me know that this solution works at all. I assume I could find out the AXDescription in german using some XCode tools (Accessability inspector) is this right or is there an easier way?
    – Fyn
    Nov 27 '20 at 17:58
  • 1
    @Fyn, See the updated answer, specifically the code under "For other languages, including English, try the following example AppleScript code". I believe it will work while using German as the language in System Preferences . Nov 27 '20 at 18:48
  • Yes works like a charm using German. I could even reduce the delay down to 0.01 but that may only work because I have already sped up animations in Terminal.
    – Fyn
    Nov 27 '20 at 19:15
  • I have asked a similar / followup question here maybe you can reuse your wisdom, thanks
    – Fyn
    Nov 27 '20 at 20:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .