Sam's Website Propeller Hat Icon

Scripting the Unscriptable: Screen Sharing in macOS Sonoma

macOS Sonoma’s new Screen Sharing app comes with a cool “High Performance” mode for Apple Silicon Macs. It looks great, but I have a gripe. For the longest time, I’ve had a single-serve Alfred workflow that opens a Screen Sharing connection to my home server (an M1 Mac mini) using this shell script:

open vnc://[email protected]

This is what Merlin Mann would call a no look pass. I use it all the time for quick in-and-out maintenance jobs and, in previous versions of macOS, the Screen Sharing app would immediately open a new connection. No questions asked.

The Problem

When I open a Screen Sharing connection with the vnc:// URI scheme in Sonoma, Screen Sharing now gives me this prompt…

A modal prompt from the new Screen Sharing app in macOS Sonoma reading "Select Screen Sharing Type:" and then giving two options selectable via radio buttons: "Standard" (selected by default) and "High Performance"

This dialogue appears every time you open a new connection and it does not remember your choice. Switching to “High Performance” mode currently requires me to mouse over and click the radio button myself. I probably did that half a dozen times before I gave up and just started hitting return to shoo away the dialogue. That means I almost always run Screen Sharing in “Standard” mode which is a real pity.

Scripting the Unscriptable

As far as I can tell, there’s no officially-supported way to programmatically start a “High Performance” connection. So hold my beer… We’re doing UI scripting.

The main headache with UI scripting is extracting information from macOS about which elements are there to be scripted. Without information about an app’s accessibility structure, there’s no hope of gluing together an AppleScript with the right tell statements. There are a few helpful utilities out there…

I ended up using Chris Stone’s script because it’s free and I could get it working immediately. This is the output it produced for the Screen Sharing dialogue…

application Process "Screen Sharing"
	window 
		group 1
			UI element 1
			radio group 1
				radio button 1
				radio button 2
			button 1
			button 2
			button 3
		static text 1

After a bit of wrangling with Script Editor, this is where I ended up…

tell application "System Events"
	tell process "Screen Sharing"
		-- replace with your target computer's details
		open location "vnc://[email protected]"
		
		-- wait for UI to load
		activate
		repeat until (count of windows) = 1
			delay 0.05
		end repeat
		
		-- click "High Performance"
		click radio button 2 of radio group 1 of UI element 1 of window 1
		
		-- click "Continue"
		click button 3 of group 1 of window 1
	end tell
end tell

Bingo. I still get a brief flash of the mode selection screen but at least it no longer stops me in my tracks. It’s a crying shame that nobody within Apple had the time (or the inclination) at add proper scriptability to this otherwise-great upgrade.

Maybe in macOS 15.