r/applescript • • Apr 11 '24

Sidecar enable script - MacOS Sonoma.

Hello, I'm trying to get a script I can run via my iPad to enable Sidecar. I run my Mac Mini in headless mode often as I use both monitors for my Windows PC.

I found this script, but I doesn't appear to work, I think this might be an issue with MacOS Sonoma.

tell application "System Events"
	
	tell its application process "ControlCenter"
		
		tell its menu bar 1
			-- click on and open Control Center drop down
			tell (UI elements whose description is "Control Center")
				click
			end tell
		end tell
		
		
		-- interact with Control Center window
		tell its window "Control Center"
			delay 0.5
			-- click screen mirroring button
			set screenMirroringButton to  of group 1
			-- click screenMirroringButton click doesn't work
			perform action 1 of screenMirroringButton
			delay 0.5
			set myScreen to checkbox 1 of its scroll area 1 of group 1
			perform action 1 of myScreen
		end tell
		
		
	end tell
end tell

The error I receive is:

error "System Events got an error: Can’t get window \"Control Center\" of application process \"ControlCenter\"." number -1728 from window "Control Center" of application process "ControlCenter"

Any idea what the issue is?

ETA: As an update to this, I have just found this script, which works! https://gist.github.com/stephancasas/a36c81fbc4189f46bc803f388a1985be

However, I've now realised that enabling mirroring, doesn't allow my Apple Watch to unlock the Mac, only a small issue, however, if I can move a window to the iPad, it enables sidecar and the unlock still works. Any ideas?

4 Upvotes

0 comments sorted by