2

Attempting to start a screen recording, wait a few seconds, stop the recording and export saved recording to disk.

Versions

  • AppleScript 2.2.4
  • QuickTime: 10.2

AppleScript

set filePath to "" & (path to desktop)

tell application "QuickTime Player"
    set newMovieRecording to new movie recording
    tell newMovieRecording
        start
        delay 2 --(seconds)
        stop
        export newMovieRecording in (filePath & "movie") using settings preset "25 fps"
    end tell
end tell

The stop and start commands work correctly but the export command is giving failing with this error:

movie_record.scpt:215:294: execution error: QuickTime Player got an error: Can’t get document "Movie Recording". (-1728)

2 Answers 2

4

Notice the name of the document changes after the stop command is issued...

set filePath to (path to desktop as text) & "movie.mov"

tell application "QuickTime Player"
    set newMovieRecording to new movie recording
    set windowID to id of first window whose name = "Movie Recording"

    tell newMovieRecording
        start
        delay 2 --(seconds)
        stop
    end tell

    set newMovieRecordingDoc to first document whose name = (get name of first window whose id = windowID)
    tell newMovieRecordingDoc to export in filePath using settings preset "iPod"
    --tell newMovieRecordingDoc to export in filePath using settings preset "25 fps"
end tell
4
  • I ran your suggested code block and while the export command did not throw an error, QuickTime did not save anything to disk and the recording window was still open. Can you verify that QuickTime saves the file to the specified location on your Mac?
    – cooncesean
    Jun 26, 2013 at 21:23
  • I wrote and tested it in Snow Leopard. I can check the latest version tonight.
    – adayzdone
    Jun 26, 2013 at 21:39
  • Can you explain the difference between save and export? Do I need to call one before the other? I have save newMovieRecording in filePath working (it pulls up this dialogue: cl.ly/image/0s3O0r0D0c1c), but the file still isn't being "saved" to disk.
    – cooncesean
    Jun 26, 2013 at 21:50
  • In Mountain Lion, I get an error even after resolving the document reference by simply referring to it as document 1. It is giving me a permission error
    – adayzdone
    Jun 27, 2013 at 14:32
2

Found a solution. Note that there is a slight delay (about ~2 seconds) from the time the script is invoked until the recording actually begins.

(*********************************************
Record a Single `QuickTime` Movie
Args:
    1. name: The name of the movie.
    2. seconds: The length of the movie you want to record in seconds.
Usage:
    > osascript movie_record.scpt 'name.mov' 5
    > osascript movie_record.scpt <file_name> <seconds>
**********************************************)
on run argv
    set movieName to item 1 of argv
    set delaySeconds to item 2 of argv
    set filePath to (path to desktop as text) & movieName
    set f to a reference to file filePath

    tell application "QuickTime Player"
        set newMovieRecording to new movie recording

        tell newMovieRecording
            start
            delay delaySeconds
            pause
            save newMovieRecording in f
            stop
            close newMovieRecording
        end tell
    end tell
end run
2
  • I want to record screen till the execution of my terminal command ends (want to enhance feature without delay) can you help me with the same Jun 3, 2015 at 10:00
  • I get permission denied to save if I give path instead of file name by changing the script Jun 6, 2015 at 9:15

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.