I am trying to automate playback to appletv via airplay. I need it to be able to open video files passed from terminal and then send it (using quicktime player) to appletv. Right now i have the following script:
To AirplayStream(aFile)
tell application "QuickTime Player"
activate
try
set frontDoc to front document
close front document
on error err number errNum
if errNum is -1719 then
-- There is no open document
else if errNum is -10000 then
-- Front doc exists, but does not really...
else
log err
end if
end try
open aFile
tell application "System Events" to tell process "QuickTime Player"
tell window 1
click button 4
delay 1
pick menu item "AppleTV" of menu 1 of button 4
end tell
end tell
play front document
end tell
end AirplayStream
on run
set unixFile to "path/to/file"
set macFile to POSIX file unixFile
set fileRef to macFile as alias
my AirplayStream(fileRef)
end run
When i run it i get to a point, where the airplay button is clicked and then i get an error “Can’t get menu 1 of button 4 of window 1 of process “QuickTime Player”. Invalid index”. I tried many combinations of indexing and none seem to work.
I am on MacOS 12.