new space run task then close space

I have a stay running script that hides the dock and opens two side-by-side finder windows then when Finder quits it shows the dock. I would like the script to open a new mission control space before this and then close it when the script ends. is this possible?

It is possible with help of some mouse tool.


-- script: Adds new space (Mission Cintrol)
tell application "Mission Control" to launch
tell application "System Events" to tell process "Dock" to set frontmost to true
delay 0.02
do shell script "/usr/local/bin/cliclick m:1250,20" -- mouse move 
delay 0.02
do shell script "/usr/local/bin/cliclick c:1250,75" -- click "+" button

To switch to the space 1, something like this:


tell application "System Events" to keystroke "1" using {control down}

NOTE: check the keyboard shortcuts is activated (go System Preferences–>Keyboard–>Application Shortcuts–>Mission Control)

The same without using third-party mouse tool:


property commonPart : "/usr/bin/python <<END
import time
from Quartz.CoreGraphics import CGEventCreateMouseEvent
from Quartz.CoreGraphics import CGEventCreate
from Quartz.CoreGraphics import CGEventPost
from Quartz.CoreGraphics import kCGEventLeftMouseDown
from Quartz.CoreGraphics import kCGEventLeftMouseUp
from Quartz.CoreGraphics import kCGMouseButtonLeft
from Quartz.CoreGraphics import kCGHIDEventTap
from Quartz.CoreGraphics import CGEventGetLocation
from Quartz.CoreGraphics import kCGEventMouseMoved
def mouseEvent(type, posx, posy):
          theEvent = CGEventCreateMouseEvent(None, type, (posx,posy), kCGMouseButtonLeft)
          CGEventPost(kCGHIDEventTap, theEvent)
def mousemove(posx,posy):
          mouseEvent(kCGEventMouseMoved, posx,posy);
def mouseclick(posx,posy):
          mouseEvent(kCGEventLeftMouseDown, posx,posy);
          mouseEvent(kCGEventLeftMouseUp, posx,posy);
ourEvent = CGEventCreate(None);"

tell application "Mission Control" to launch
tell application "System Events" to tell process "Dock" to set frontmost to true
delay 0.02
my mouseMove(1250, 20) -- mouse move 
delay 0.02
my mouseMove(1250, 75) -- mouse move 
delay 0.02
my mouseClickWithoutRestore(1250, 75) -- click "+" button

--------------------------------------- The Handlers ---------------------------------------
on mouseMove(x, y)
	do shell script commonPart & "
mousemove(" & x & "," & y & ");  
END"
end mouseMove

on mouseClickWithoutRestore(x, y)
	do shell script commonPart & "
mouseclick(" & x & "," & y & ");
END"
end mouseClickWithoutRestore

on mouseClick(x, y)
	do shell script commonPart & "
currentpos=CGEventGetLocation(ourEvent);
mouseclick(" & x & "," & y & ");
mousemove(int(currentpos.x),int(currentpos.y));
END"
end mouseClick