How can I switch the screen to my iPad in QuickTime using AppleScript?

Hey,

How can I switch the screen to my iPad in QuickTime using AppleScript? I’ve successfully changed the camera and microphone settings, but I’m having trouble with the screen.
image

Does anyone have any suggestions?

Here is my current AppleScript:

on run {input, parameters}
	
	if (count of input) = 0 then
		set input to {"My iPad"}
	end if
	set targetName to item 1 of input as text
	
	tell application "QuickTime Player"
		activate
		set newRec to new movie recording
		-- ↓ only the next line is changed ↓
		-- set newRec's current screen to (first screen whose name contains targetName)
	end tell
	
	return input
end run

I don’t see any way to do this directly - the screen does not appear to be a parameter exposed via AppleScript, mostly because the iPad is used as an extended display and isn’t part of the document properties

That leaves you with two approaches.

First you can query the OS to find the attached displays:

use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use framework "AppKit"
use scripting additions


set allDisplays to (current application's NSScreen's screens()) as list

then parse the results to find the iPad extended display. Then you can move the document to the coordinates of the iPad display (taken from the allDisplays variable, above).

set bounds of newRec to <coordinates of Sidecar display>

Alternatively, use UI Scripting to select the 'Move to " menu option in the Window menu.

I’m not referring to Sidecar or using the iPad as an extended display. I want to select my iPad as the screen source in a new QuickTime movie recording when it’s connected via cable (Think of cabled AirPlay). I can do this manually from the dropdown menu next to the record button, but I want to automate using Apple Script.

I’m not referring to Sidecar or using the iPad as an extended display.

YOU might not be referring to Sidecar, but that is the exact underlying mechanism that is used when you opt to display the recording on your iPad - the OS establishes a Sidecar connection to your iPad and the app moves the recording display to the iPad screen coordinates.

You can test (and prove) this yourself by querying the displays ‘attached’ to your Mac when running a recording. You’ll see the iPad listed as a secondary display.