I was using the following AppleScript on my iMac to automatically connect to an iPad using Sidecar.
set deviceName to "Michael’s iPad Pro 12.9"
tell application "System Events"
tell process "SystemUIServer"
click (menu bar item 1 of menu bar 1 whose description contains "Displays")
set displaymenu to menu 1 of result
if ((menu item 1 where its name starts with deviceName) of displaymenu) exists then
-- Not connected, so click the name of the device to connect
click ((menu item 1 where its name starts with deviceName) of displaymenu)
else
-- Connected, so click "Disconnect" to disconnect
click ((menu item 1 where its name starts with "Disconnect") of displaymenu)
end if
end tell
end tell
However, this no longer works on Big Sur (macOS 11.0.1). Can anyone tell me how I can modify this script so it will work again?
Model: iMac Pro
AppleScript: 2.7
Browser: Safari 537.36
Operating System: macOS 10.14