Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
AppleScript to Mirror iPhone to QuickTime
set deviceName to "Kevin’s iPhone"
activateScreenKeepAwake()
readyQuickTime()
setVideoInput(deviceName)
setAudioInput(deviceName)
setVolume(1.0)
setScreenSize("maximize")
# ----- Functions -----
on activateScreenKeepAwake()
do shell script "open keepingyouawake:///activate"
end activateScreenKeepAwake
on readyQuickTime()
tell application "QuickTime Player"
set newMovieRecording to new movie recording
end tell
tell application "System Events" to tell process "QuickTime Player"
set frontmost to true
end tell
end readyQuickTime
on openInputsMenu()
ignoring application responses
tell application "System Events" to tell process "QuickTime Player"
click button 2 of window 1
delay 1
end tell
end ignoring
do shell script "killall 'System Events'"
end openInputsMenu
on setVideoInput(inputName)
my openInputsMenu()
tell application "System Events" to tell process "QuickTime Player"
set inputMenu to menu 1 of button 2 of window 1
set inputList to name of every menu item of inputMenu
repeat with menuItemPosition from 1 to length of inputList
if item menuItemPosition of inputList is inputName then
ignoring application responses
click menu item menuItemPosition of inputMenu
exit repeat
end ignoring
end if
end repeat
end tell
end setVideoInput
on setAudioInput(inputName)
my openInputsMenu()
tell application "System Events" to tell process "QuickTime Player"
set inputMenu to menu 1 of button 2 of window 1
set inputList to name of every menu item of inputMenu
set skippedFirstInstance to false # First one is for video, second instance is audio
repeat with menuItemPosition from 1 to length of inputList
if item menuItemPosition of inputList is inputName then
if skippedFirstInstance is true then
click menu item menuItemPosition of inputMenu
exit repeat
else
set skippedFirstInstance to true
end if
end if
end repeat
end tell
end setAudioInput
on setVolume(volumeValue)
tell application "System Events" to tell process "QuickTime Player"
tell slider 1 of window 1
set its value to volumeValue
end tell
end tell
end setVolume
on setScreenSize(method)
tell application "System Events" to tell process "QuickTime Player"
if method is "fullscreen" then
set value of attribute "AXFullScreen" of window 1 to true
end if
if method is "maximize" then
delay 3 # Gives time for the video to show up with right aspect ratio
perform action "AXZoomWindow" of (first button whose subrole is "AXFullScreenButton") of window 1
end if
end tell
end setScreenSize
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment