Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

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
        start
        delay 10
        stop
    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.

share|improve this question
add comment

2 Answers 2

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.

share|improve this answer
    
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 Sep 5 '12 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 Sep 5 '12 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 Sep 5 '12 at 14:52
    
Another 10.8 note: My screen recordings don't automatically get saved under ~/Movies. –  Greg W Sep 5 '12 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 Sep 5 '12 at 17:41
show 3 more comments

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/

share|improve this answer
    
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 Feb 20 '13 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 Feb 20 '13 at 21:18
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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