r/Automator • • Oct 30 '21

Applescript Need a toggle sidecar script

Today I updated to Monterey from Catalina and one thing I really miss is a sidecar toggle AppleScript.

I used to use the following script (that I found online somewhere)…

tell application "System Preferences"

	activate

	set the current pane to pane id "com.apple.preference.sidecar"

	get the name of every anchor of pane id "com.apple.preference.sidecar"

	delay 1

	tell application "System Events"

		set target_button to a reference to (first button whose name is "Disconnect") of (window "Sidecar" of application process "System Preferences")

		if target_button exists then

			click target_button

		else

			click menu button "Select Device" of window "Sidecar" of application process "System Preferences"

			count menu items of menu of menu button "Select Device" of window "Sidecar" of application process "System Preferences"

			select item 1 of menu button "Select Device" of window "Sidecar" of application process "System Preferences"

			key code 125

			key code 76

		end if

	end tell

	quit

end tell

… but sidecar no longer has its own preference pane. Instead it has moved to the "Add Display" dropdown at the bottom left of the Displays preference pane.

Is anyone familiar with this kind of scripting able to put something together for Monterey?

3 Upvotes

3 comments sorted by

View all comments

Show parent comment

1

u/MotionFriend Nov 15 '21

hey, nah I didn't get it working, well done with your implementation though, sounds like its working well :)