I’m trying to write an AppleScript that will take a list of file names (e.g., X) and do the following for each one:
-Open the video file X.mov and the sound file X.wav in QuickTime 7 Pro
-Merge the sound file with the video file and save the result
I’m brand new to AppleScript, but it doesn’t seem like this should be very difficult. Here was my first attempt at doing this:
set mainFolder to (path to desktop folder as text)
set fileList to {"fileNameA", "fileNameB"}
repeat with nextFile in fileList
-- identify audio and video files
set audFile to (mainFolder & nextFile & ".wav")
set vidFile to (mainFolder & nextFile & ".mov")
tell application "QuickTime Player 7"
activate
-- copy audio track
open audFile
rewind audFile
select all audFile
copy audFile
-- prepare video track for audio overlay
open vidFile
rewind vidFile
select all vidFile
-- add audio track to video track
tell application "System Events"
tell application "QuickTime Player 7" to activate
key code 9 using {command down, option down}
end tell
-- save and close files
save vidFile
close audFile
close vidFile
end tell
end repeat
The key code 9 + command + option line is intended to replace the “add” command, which didn’t seem to work at all; command-option-v is the shortcut within QuickTime for adding a track, and it occasionally works.
Which brings me to the issue I’m facing: As far as I can tell, sometimes this script partially works, and sometimes it doesn’t work at all (usually the latter). Issues include:
-The program always opens the correct files in the correct order, but tracks are sometimes still mismatched. For example, A.wav is often overlaid on both A.mov and B.mov. QT actually seems to get stuck, such that if I quit the program and rerun the script while excluding A from fileList, it sometimes still overlays A.wav on B.mov.
-Often (but not always), the program doesn’t overlay any audio over any video at all. Instead, it changes the video files somehow, either displaying garbled characters at the bottom or - in a couple of cases - part of the script. For example, the words “set FileList” once appeared within the video.
-The video file doesn’t save.
-The video and audio files don’t close.
The sheer number of issues with this script and the inconsistency from one run to the next have me more than a bit flummoxed. I searched the forums to look at other people’s QT scripts, but didn’t see any reports of people having encountered any problems like this. Any advice/comments would be welcome!