MacOS – Create a New Space in Mavericks using Applescript

applescriptmacosmission-controlspaces

In Mavericks, is it possible to use Applescript to create a new Space in Mission Control?

I also tried the following code to switch to another Space, but it does not seem to do anything…

tell application "System Events"
    tell process "Finder"
        keystroke "2" using control down --switches to space 2
    end tell
end tell

Best Answer

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

You can download MouseTools from http://www.hamsoftengineering.com/codeSharing/MouseTools/MouseTools.html. See http://osxnotes.net/applescript.html for a list of key codes.