Opening New Desktop Space on macOS Sonoma

I used the following script to open new space in Ventura, after updating the new OS the script no longer works. Does anyone know any solution, If there’s an alternative way please share.

tell application "System Events"
	do shell script quoted form of "/System/Applications/Mission Control.app/Contents/MacOS/Mission Control"
	click button 1 of group "Spaces Bar" of group 1 of group "Mission Control" of process "Dock"
	do shell script quoted form of "/System/Applications/Mission Control.app/Contents/MacOS/Mission Control"
end tell

TIA

This script have been tested on Ventura.

tell application "System Events" to tell application process "Dock"
	key code 160
	delay 1
	tell group 2 of group 1 of group 1
		click (buttons whose description is "add desktop")
	end tell
end tell

1 Like

Thanks for the script it works on the macOS Sonoma 14.1.1

I added the following

tell application "System Events" to tell application process "Dock"
	key code 160
	delay 1
	tell group 2 of group 1 of group 1
		click (buttons whose description is "add desktop")
	end tell
	delay 0.25
	key code 53 --  # Esc key on US English Keyboard
end tell

Fredrik71. This doesn’t work on my Sonoma computer. Does something need to be showing in the Dock for this to work?

I do not have access to Sonoma, the script was running in Script Editor on Ventura.
@peavine

You could try to use:

return class of UI elements

After the delay repeat the process to build your tell block.

1 Like