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
        delay 3
    end tell
    tell last item of documents
    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.

  • h_value__lux, Welcome to Ask Different! I have tested the code shown in your question and it worked without issue. – user3439894 Apr 23 '20 at 15:58
  • Thanks for trying it out. I wonder what I am doing wrong. I copied and pasted it into Applescript and I still get the error message. – h_v_lux Apr 23 '20 at 19:26
  • If you are using Catalina, then there is a different way of doing it: apple.stackexchange.com/questions/374076/… – Mateusz Szlosek Apr 23 '20 at 19:36
  • h_value__lux, Sorry, I tested your code under macOS High Sierra and testing now under macOS Catalina it does fail with the error message your stated. See my answer: A: How to screen record using AppleScript on Catalina? – user3439894 Apr 23 '20 at 19:51

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.

  • The result of running your code in macOS Catalina is: 'error "System Events got an error: Can’t get menu bar 1 of application process \"screencaptureui\". Invalid index." number -1719 from menu bar 1 of application process "screencaptureui"' – user3439894 Apr 23 '20 at 19:57

You must log in to answer this question.

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