I want to connect to the iPad via universal control, but this script is still missing the last step.
It also needs to click on the device with the name ipad to connect. Can you tell me what other code needs to be added?
My system is monterey 12.5.
tell application "System Events"
tell its application process "ControlCenter"
click menu bar item "Control Center" of menu bar 1
tell its window "Control Center"
-- Monterey
if exists checkbox "Screen Mirroring" then
tell its checkbox "Screen Mirroring"
perform action 2
delay 1
end tell
end tell
else
-- big sur
-- "action 1" instead of "action 2"
if exists (checkbox "Screen Mirroring" of group 1 of group 1) then
tell its checkbox "Screen Mirroring" of group 1 of group 1
perform action 1
delay 1
end tell
end if
-- ventura??
-- "Screen Mirroring" is inside a "group 1"
if exists (checkbox "Screen Mirroring" of group 1) then
tell its checkbox "Screen Mirroring" of group 1
perform action 2
Here are some details

Execute an AppleScript.kmactions (1.5 KB)

A solution was found:
tell application "System Events" to tell process "ControlCenter"
click menu bar item "Control Center" of menu bar 1
perform action 2 of checkbox "Screen Mirroring" of window "Control Center"
delay 2
tell window "Control Center"
click (first checkbox of scroll area 1 whose name starts with "iPad")
end tell
end tell
Does this just start sidecar?
Yeah, I hope it's connected to the iPad.
Awesome, but isnāt it possible for this to connect to the wrong iPad if thereās more than one?
A device whose name starts with āiPadā and is related to this.
I recently found and tested a script called SidecarLauncher that handles the connection via the command line, and makes for a much more seamless connection experience. I pasted an image of my version of the macro below, along with the āmove dockā script Iām using to reposition my dock (since I have my iPad as a display beneath my MacBook, which causes the Dock and unfortunately also the āTab switcher to move with it).
(Iām guessing I can probably handle the connection checks as a script instead of using a variable, too, but I retrofitted this macro from an older implementation that opened System Preferences to push buttons).
Connect to Sidecar
Move Dock from Bottom to Left (and vice versa)
2 Likes