0

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.

4
  • h_value__lux, Welcome to Ask Different! I have tested the code shown in your question and it worked without issue. 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/… 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? Apr 23 '20 at 19:51
-1

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.

1
  • 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"' Apr 23 '20 at 19:57
-1

To stop the recording I did this and it worked fine, just change the delay seconds to 3600 (60 minutes), this will press control + cmd + esc to stop the screen recording after 5000 seconds

tell application "System Events"
    delay 5000
    key code 53 using {control down, command down} -- shift-command-left
end tell

I haven't researched how to start it, I started it manually

You must log in to answer this question.

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