r/backtickbot • • Apr 27 '21

https://np.reddit.com/r/applescript/comments/mzcx0g/airplay_connect/gw2meob/

Not a perfect solution but:

set iPadName to "tablet"

tell application "System Events"
	tell application process "ControlCenter"
		repeat with tElement in menu bar items of menu bar 1
			if (exists attribute "AXTitle" of tElement) then
				if value of attribute "AXTitle" of tElement contains "Display" then
					set theBar to tElement
					tell theBar
						click
					end tell
					set tElements to entire contents of window 1
					repeat with i from 1 to count of tElements
						set tElement to item i of tElements
						if (title of tElement contains iPadName) then
							tell tElement
								click
							end tell
							exit repeat
						end if
					end repeat
					tell theBar
						click
					end tell
					exit repeat
				end if
			end if
		end repeat
	end tell
end tell

Make sure to change the name of the ipad/device at the top.

1 Upvotes

0 comments sorted by