Question

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.

Was it helpful?

Solution

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
Licensed under: CC-BY-SA with attribution
Not affiliated with apple.stackexchange
scroll top