Can Applescript be used to automate a screen recording session on OS X?

Try this script:

tell application "QuickTime Player"
    set newScreenRecording to new screen recording
    tell newScreenRecording
        start
        delay 3
        stop
    end tell
    tell last item of documents
        close
    end tell
end tell

It will make a new recording for 3 seconds (edit the delay 3 line to change the length), which gets automatically saved in the Movies directory of your Home directory, then closes the recording window.

If you want to automatically export to a different format, you can do that by adding the line export in ("" & (path to desktop) & "quicktimeFile.m4v") using settings preset "480p" before the close line. The presets you can choose from are defined in the File > Export dialog:

export options

Check the actual dialog for further details on the presets (note that they are "up to" the resolution listed - it will fit into the horizontal pixels available, so "480p" gives you 640x400 for a 16:10 recording). As far as I know, you can't make custom presets.

If you want to capture your system sounds, and not mic/line-in audio, check out this question: Can I get system sound along with QuickTime Player screen recording?

For the curious, there are a couple notes about why the original script doesn't work and QuickTime Player's AppleScript peculiarities:

  • The set newDoc […] line tries to grab the most recent document with the string "Untitled" to account for the newScreenRecording reference becoming invalid once the recording is stopped (which is probably a poor design decision, but oh well). However QuickTime Player under Lion (and possibly Snow Leopard) auto-saves screen recordings as "Screen Recording", "Screen Recording 2", etc., so it was finding no documents. Having it grab just the most recent document solves this, and future proofs it to a degree.

  • The export line references a preset that no longer exists (or has been renamed). Unfortunately neither QuickTime nor AppleScript gives any errors about this, it simply fails silently (more poor design).

  • The AppleScript dictionary for QuickTime Player lists a save action, but I couldn't get it working—I suspect the functionality was killed, but the dictionary entry wasn't removed. You'll note that there's no Save functionality in the GUI, only export (and auto-save). So if you want to change the save location without exporting a new file, you'll have to get the file location, then move it through the Finder.


I recently wrote a script which does not depend on the version of QuickTime at all.

It just simulates actual user actions to save/export the movie. It takes as input the directory you want the movie file to be exported to, and the number of seconds you want to recording to go on for.

Check out the script (and the associated blog post) at http://www.neerajkumar.net/blog/2013/02/16/script-to-record-screen-on-mac-osx-and-save-on-disk/