Hi all, fyi this works for me on Ventura 13.4.1 (change the name of your iPad in the Script...)
Add or Remove iPad as External Display.kmmacros (13 KB)
For more information, see the wiki Searching the Forum for Answers section.