Create a new space using a keyboard shortcut

Solution 1:

Update: This method works in OS X 10.11 and earlier at least to OS X 10.8 (didn't test it on anything older then OS X 10.8) but no longer works as coded in macOS 10.12 due to significant changes to Mission Control made by Apple.


To programmatically add a Desktop in Mission Control the code below can be used as an AppleScript or a BASH Script in conjunction with an Automator Service using Run AppleScript or Run Shell Script, respectively, and a key sequence assigned to the Service in System Preferences in Keyboard Shortcuts.


AppleScript Code:

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 1 of process "Dock"
delay 0.5
tell application "System Events" to key code 53

BASH Script Code:

#!/bin/bash

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

  • Open Automator and select Service.

  • Set: Service receives no input in any application

  • Add either a Run AppleScript or Run Shell Script Action.

  • Add the appropriate code for the target Action.

  • Save the Service as, e.g.: Add New Desktop

  • Assign a keyboard shortcut for the Service in System Preferences.

Note: You'll have to assign a key sequence that is not used elsewhere on the System or in Finder if you choose is over any application in the Service.

I tested it with: ⌃⌥⌘D (Control-Option-Command-D)

Solution 2:

OK, using the Automator recording, I made it work with a revised version of the AppleScript in the other answer.

Replace "of group 1" with "of group 2 of group 1 of group 1 of":

on run {input, parameters}

    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

    return input
end run

Solution 3:

Yep, that works, sort of. Problem is that user3439894's solution ends up throwing an error if the active application (Finder, textedit, etc.) hasn't been added to the Security & Privacy Accessibility pane.

To get around this, we need two workflows, user3439894's service with the updated group list as an Automator application, and a second Automator service to launch it.

The Automator Application (Saved into /Applications as "New Desktop".)

on run {input, parameters}

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

return input

end run

Then we just need to create the second workflow as a service, using the "Launch Application" action and save it as "New_Desktop"

Last steps are to add “New Desktop.App” to  System Preferences > Security & Privacy > Accessibility

Then add your keyboard shortcut in System Preferences > Keyboard > Shortcuts > Services > General for the New_Desktop.workflow.