3

I'm working on a project that requires me to record a large number of 20-second audio clips (the file format is unimportant, as far as I'm aware). I would like to be able to do this without pressing a button to stop each recording—that is, I'm hoping there's a way that I can use a timer to stop recording automatically each time 20 seconds is up. Can I manage this in QuickTime? If not, I'm open to any suggestions the community may have. Thanks in advance.

3
  • Have your tried using AppleScript to do this? Jul 28 '15 at 0:32
  • I should have mentioned that I'm a new-ish Mac user... haven't delved into AppleScript, yet. Is it a simple solution, in this case? Jul 28 '15 at 1:10
  • Well "simple" is a relative term and with being new to OS X it may be difficult however if you're looking to automate the process then it can be done. I'll post and example as an answer. Jul 28 '15 at 3:30
3

This is a sample script to try and fit the needs/wants you expressed. As coded it's going to make 3 five second recordings on your Desktop named "Recording_n.m4a" when 'n' in the name will be incremented automatically 1 to 3, e.g. "Recording_1.m4a", "Recording_2.m4a" etc. to whatever howMany is set to.

Open Script Editor and copy and paste the code below and press the "Compile" button.

set howMany to 3 -- The number of recordings to make.

set recordingNumber to 1 -- 'recordingNumber' is used to increment the recording number in the filename when exporting.

tell application "QuickTime Player"
    activate
    close (every document whose name contains "Untitled") saving no -- I set this just to have no other Untitled windows open when starting the recordings, especially if having broken out of the repeat loop.
    repeat howMany times
        set savePath to (the path to the desktop folder as text) & "Recording_" & recordingNumber & ".m4a"
        set recording to new audio recording
        start recording
        delay 6 -- Add an additional second to the wanted value, e.g. for 20 second recording set delay to 21.
        stop recording
        export document "Untitled" in file savePath using settings preset "Audio Only"
        delay 2 -- Set appropraite delay to allow export to complete.
        close (every document whose name contains "Untitled") saving no
        set recordingNumber to recordingNumber + 1 -- Increments recording number by one.
        -- Close "Export Progress" window.
        tell application "System Events" to click menu item "Hide Export Progress" of menu "Window" of menu bar 1 of process "QuickTime Player"
        display dialog "Click OK or press Enter to start next recording."
    end repeat
end tell

Run the script as is a time or two so you can see what it's doing and then you can change the value of howMany to the number of recordings you want/need to make, change the value of the first delay from '6' to '21' for a 20 second recording and the value of the second delay from '2' to e.g. '5'. The value of the second delay you'll need to determine ahead of time by setting the value of howMany to 1 or 2 and the value of the first delay from '6' to '21' so you have a 20 second recording to see how many seconds it takes to export. This value (of the second delay) can be higher then actually needed, say if you want a little break between recordings to catch your breath and collect your thoughts for the next recording, although there is another control in the form of a dialog message box between each recording.

Note the line display dialog "Click OK or press Enter to start next recording.", it's there as a control mechanism to start the next recording or to break out of the repeat loop. There are many different of ways to code and accomplish a task like this and this is just meant to give you a starting framework to build upon if you want to use AppleScript to accomplish an automated task such as you've mentioned.

There is no error checking written into this script as is, meaning if the script is run a second time it will overwrite e.g. "Recording_1.m4a", "Recording_2.m4a" etc. So if you need to break out of the repeat loop by clicking "Cancel" in the dialog message box or "Stop" in the Script Editor, make sure you set recordingNumber to the appropriate number, which would be the number used of the last exported file + 1. Also, the first close (every document whose name contains "Untitled") saving no line will close any file opened in QuickTime Player whose name contains "Untitled" without saving it or prompting to be saved. It can be commented out by placing -- in front of it if you wish although if you broke out of the repeat loop you'll have to manually cleanup before restarting so you may want to leave it as is. Just when using this script only use QuickTime Player for the task at hand if you don't understand why I coded it this way.

4
  • Wow, thanks. This does the trick. I'm also impressed at how human-readable AppleScript is. I'm just wondering... how would I specify a certain folder on the desktop (e.g., "Recordings") for the saved recordings? Jul 28 '15 at 14:49
  • @hrbellemare, It can be added different ways, here's one way. In the set savePath to line... add & "Recordings:" in front of & "Recording_" so that line would read, set savePath to (the path to the desktop folder as text) & "Recordings:" & "Recording_" & recordingNumber & ".m4a". Jul 28 '15 at 15:16
  • Thanks. One thing that I would add, for anyone reading, is that the folder has to exist in order for this to work -- it won't be created by the script. Aug 2 '15 at 18:23
  • @Harold Bellemare, You'er welcome! As I said "There is no error checking written into this script as is" and while I mentioned it in the context of overwriting files it creates it was also applicable in general. Remember the script I provided was a "sample script" and also said "and this is just meant to give you a starting framework to build upon" so proper error handling and additional functionally certainly can be built into the script at ones choosing. :) Aug 2 '15 at 18:56

You must log in to answer this question.

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