I need to accomplish the following tasks from a script:

  1. Initiate a screen recording (with system audio).
  2. After a set delay, stop the recording.
  3. Save out to a file.
  4. Close the recording.

I've tried a few different approaches here and ran into roadblocks. One thing I've tried for example was a QuickTime script found here.

tell application "QuickTime Player"
    set newScreenRecording to new screen recording
    tell newScreenRecording
        delay 10
    end tell
    set newDoc to last item of (documents whose name contains "Untitled")
    set f to "" & (path to desktop) & "quicktimeFile"
    export newDoc in f using settings preset "Quicktime Movie"
end tell

This script doesn't error, but it doesn't save anything either.

In the past I've used iShowU HD, but I've ran into significant performance issues there which have caused me to go back to the drawing board.

I'm willing to pay for a third-party application provided that it meets my requirements, so feel free to suggest anything that could get the job done.

Running OS X 10.8 Mountain Lion.

3 Answers 3


Try this script:

tell application "QuickTime Player"
    set newScreenRecording to new screen recording
    tell newScreenRecording
        delay 3
    end tell
    tell last item of documents
    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.

  • Ok, I was able to get the export line to work thanks to your insight. Now I have another issue: It looks like Applescript does not wait for the export line to complete before moving on to the next line. If I close the recording window before the export is finished, it fails. So I guess somehow I need to figure out how long an export will take, delay that amount, then close the window.
    – Greg W
    Commented Sep 5, 2012 at 13:35
  • That's odd, not the behaviour I get. When I run the script (with the export after tell last item of documents and before close), I get a separate export window opening, running the export, then the recording window closes. But it doesn't interrupt the export process. This is using Quicktime X on Lion.
    – robmathers
    Commented Sep 5, 2012 at 14:38
  • Might be because I'm on 10.8 then (should have put that in the description, my bad). I could hard code a delay, but that feels dirty to me. Some videos could take a lot longer to export than others, so I'd be playing a guessing game.
    – Greg W
    Commented Sep 5, 2012 at 14:52
  • Another 10.8 note: My screen recordings don't automatically get saved under ~/Movies.
    – Greg W
    Commented Sep 5, 2012 at 14:52
  • Ah okay. I unfortunately don't have a 10.8 install handy to test things on. It's possible that the save command might work for you (it doesn't appear to do anything on 10.7). You could also just remove the close command and close it manually once the encode is done.
    – robmathers
    Commented Sep 5, 2012 at 17:41

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/

  • Looks nice, I'll give it a try. I ended up going back to iShowU HD because it allows me to crop to a specific area of the screen for my recording. Do you know if QuickTime allows this?
    – Greg W
    Commented Feb 20, 2013 at 14:59
  • Yes quicktime does allow you to do that. There is an export movie method where you can select the area you want to export.
    – Neeraj
    Commented Feb 20, 2013 at 21:18
  • Site is no longer available.
    – xrd
    Commented Jul 5, 2017 at 18:18
  • I don't suppose anyone has managed this with the iOS Simulator, would be pleased to hear about this.
    – Jules
    Commented Feb 8, 2018 at 21:05
  • It can be found here: gist.githubusercontent.com/neerajcse/4989886/raw/… Commented Feb 26, 2019 at 15:51

Not using applescript but still useful; I found a solution that works really well. You're able to record with ffmpeg using an input device called avfoundation.

Details More options ffmpeg options

Here is an example command: ffmpeg -f avfoundation -pix_fmt yuyv422 -i "1:1" -t 10 -vf crop=1280:720:1:65 -r 30 output.mkv

  • You may or may not get asked to specify -pix_fmt when this option is not included; it might be worth trying other formats to see if you get better performance.
  • As explained in the details link, -i selects both video and audio input. If you want to capture audio playing on your computer, you'll need something like iShowU Audio Capture. To get that to work, you'll need to press option+F11, select iShowU Audio Capture as an input device and as an output device. You'll notice that once you select it as an output device that you can no longer hear the audio yourself through your speakers or headphones. A quick fix is opening Audio MIDI Setup, create a Multi-Output Device and adding iShowU Audio Capture and your normal output device. Select this new Multi-Output device in your sound outputs and there ya go, you can now hear the audio and have it captured. Unfortunately you aren't able to control the audio levels now...if someone knows a solution to this please let me know.
  • -t is the time in seconds to record.
  • -vf is very useful for cropping and offsetting. The current setting is cropped to 1280 width 720 height, offsetting 1 pixel to the left and 65 pixels from the top. You'll need to use a third party tool to get exact pixel measurements of your screen.
  • -r is framerate

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .