2

I have several hundred videos that are each divided into ten 2-minute segments, so I am running an AppleScript to combine these with QuickTime Player 10.4. The way it works is by pasting all the parts into one QuickTime movie (in a single window), then the script keystrokes command+W to close it. Before it closes, a "Do you want to save before closing?" dialog appears, and the script fills in my desired title and presses save.

The script is generally working, but occasionally, I get an error message from QuickTime that says "Cannot open" after the save bar has already made it to the end. When this happens, I am unable to save the combined video, even if I try it again with a different destination or by going through the export menu. (When trying to export after this occurs, I get the error "Cannot Open This media may be damaged.")

A question was asked about encountering a similar error, “cannot open” when trying to save screen recording in quicktime player, and this was the top answer:

Sounds like a permissions problem. If it’s a bug I suspect it will be fixed in a future macOS update. Not much help, I know.

Until then, you have to peek behind the curtain:

  1. Unsaved recordings are stored at ~/Library/Containers/com.apple.QuickTimePlayerX/Data/Library/Autosave Information/

  2. The file will be called Unsaved QuickTime Player Document.qtpxcomposition, or similar

  3. Show Package Contents on that file

  4. Inside is Screen Recording.mov which you can copy and keep

Unfortunately, this didn't work for me. The .qtpxcomposition file's package contents does not contain an .mov file. It only contains the file "index.qtpx".

In ~/Library/Containers/com.apple.QuickTimePlayerX/Data/Library/Autosave Information/, I have the following files:

  • "com.apple.QuickTimePlayerX.plist"
  • "Unsaved QuickTime Player Document.qtpxcomposition"

I can drag the .qtpxcomposition file to another folder, but it remains only 14 KB and QuickTime still cannot save or export it.

The videos I am combining are stored on an external hard drive, and I am saving them to a different external hard drive. I made sure in my System Settings that the hard drives are not going to sleep when inactive. So all of this is to say that I'm stumped as to why this error is occurring, and I would greatly appreciate any feedback.

Here is my full AppleScript, though I don't think it has anything to do with the error:

on run {input, parameters}

    --record subfolder list
    set subfolderList to input

    tell application "Finder"
        --get number of folders
        set numFolders to count items of input

    end tell

    --repeat for all subfolders
    repeat with n from 56 to numFolders

        tell application "System Events"
            --wait until current video finishes saving
            repeat until (not (exists window "Untitled" of application "QuickTime Player"))
                delay 5
            end repeat
        end tell

        --display warning before starting next video
        tell application "SystemUIServer"
            activate
            repeat
                display alert "Clip Combining Script will begin running. Please do not type or click on anything until next 'OK' alert appears." buttons {"Delay 10 seconds", "OK"} default button 2 giving up after 10
                set x to button returned of result
                if x is "OK" then
                    exit repeat
                else if x is "Delay 10 seconds" then
                    delay 10
                else
                    exit repeat
                end if
            end repeat
        end tell

        tell application "Finder"
            --get current folder
            set currentFolder to item n of subfolderList

            --get name of folder as text
            set folderName to name of currentFolder
            set folderText to folderName as text

            --make list of videos in folder
            set currentVideos to every file of folder currentFolder

            --count number of videos
            set numFiles to count items of currentVideos

            --open folder
            open currentFolder
            activate
        end tell

        tell application "System Events"
            --highlight first video (down arrow)
            key code 125
        end tell

        tell application "QuickTime Player"
            open item 1 of currentVideos
            delay 3
            activate
        end tell

        tell application "System Events"
            --show clips (cmd E)
            key code 14 using {command down}
            delay 1
        end tell

        repeat (numFiles - 1) times

            tell application "Finder"
                activate
                delay 1
            end tell

            tell application "System Events"

                --go down one video (down arrow)
                key code 125
                delay 1

                --copy video (cmd C)
                key code 8 using {command down}
                delay 2

            end tell

            tell application "QuickTime Player"
                activate
            end tell

            tell application "System Events"

                --go to end of first video (option right arrow)
                key code 124 using {option down}

                --paste copied clip (cmd V)
                key code 9 using {command down}
                delay 2

            end tell

        end repeat

        tell application "System Events"
            --exit clip mode (enter)
            delay 6
            key code 76
        end tell

        tell application "System Events"
            --close window (cmd W)
            key code 13 using {command down}
            delay 2

            --name file same as folder name
            keystroke folderText

            --save (enter)
            key code 76
            delay 2
        end tell

        tell application "System Events"
            --minimize QuickTime (cmd M)
            key code 46 using {command down}
            delay 2
        end tell

        --close Finder window
        tell application "Finder"
            activate
        end tell
        tell application "System Events"
            --cmd W
            key code 13 using {command down}
        end tell

        --give ok alert
        tell application "SystemUIServer"
            activate
            display alert "OK" giving up after 10
        end tell

    end repeat

    return input

end run
  • Having briefly played around with QuickTime Player in AppleScript, I can see that it suffers from sandboxing issues (limiting where files can be saved to), and AppleScript bugs, meaning things you should be able to do using AppleScript, you can't. It's quite a headache, actually. I would suggest using the command line tool ffmpeg, which is pretty much the gold standard of media manipulation, and can be automated very easily, either from bash script or from AppleScript (in a do shell script wrapper). – CJK Aug 9 '18 at 1:57

You must log in to answer this question.

Browse other questions tagged .