AppleScript: start/stop QuickTime Player screen recording on timer

applescriptquicktimescreen capture

I would like to use an AppleScript which will tell QuickTime Player to start screen recording immediately and stop screen recording after a specified length of time (e.g. 60 mins).

In my search so far, I have come across this AppleScript:

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

but I get an error message saying "the variable new screen recording is not defined". I don't know anything about programming as you can probably tell so I'd really appreciate any help you can offer with this.

Best Answer

It's not pretty, but if you click to start the video this will stop it.

tell application "QuickTime Player"
    new screen recording
end tell

--Pause for 10 seconds
delay 10

--Click the stop recording button in the top menu bar.
tell application "System Events"
    click menu bar item 1 of menu bar 1 of application process "screencaptureui"
end tell

Pro tip: Record yourself doing the action you want to automate in automator, drag and drop that operation into a new window and copy the line where it says click menu... (Remove the "\" escape characters) into a simple tell application "System Events" command. But unfortunately it doesn't work for everything.