Punch and Roll editing in Audacity on Mac OSX

Even after using almost every advanced DAW (Digital Audio Workstation) out there, I still have a soft spot in my heart for Audacity.

It’s a wonderful piece of open source software that can handle an incredible number of common audio editing tasks. One reason that people sometimes leave Audacity for commercial software (like ProTools – video below) is Audacity’s lack of Punch and Roll Editing.

As a way of giving back to the Audacity Community, I put together an AppleScript that simulates Punch and Roll.

tell application "Audacity"
  activate
  tell application "System Events"
    keystroke "k" using {shift down} -- Select to end of VO Track
    keystroke "z" -- find Zero Crossing Cut
    keystroke "x" using {command down} -- Cut the Audio
    keystroke return -- Disarms VO Track
    keystroke "b" using {command down} -- Add Label to Label Track
    keystroke "?" -- Name Label
    keystroke return -- Saves Label
    keystroke return -- Disarms LABEL Track
    keystroke (ASCII character 30) -- Up Arrow selects EDIT Track
    keystroke return -- Arms EDIT Track
    keystroke "v" using {command down} -- Pastes to EDIT Track
    keystroke return -- Disarms EDIT Track
    keystroke (ASCII character 30) -- Up Arrow selects VO Track
    keystroke return -- Arms VO Track
    keystroke ",,,,," -- back up 5 seconds
    keystroke " " -- Start playback
    delay 5 -- wait 5 seconds until end of playback
    keystroke "a" using {shift down} -- stop Playback & set cursor 
    delay 1 -- needed or the following command does not work
    keystroke "r" using {shift down} -- Record from end of track
  end tell
end tell

When activated, this script automatically cuts the audio from the cursor to the end of the VO track, places a Label at the edit point, pastes the audio to the EDIT track (in case you need it later), pre-rolls 5 seconds of your recorded audio, then starts recording again.

If you improve upon this script, let me know so I can include your changes here.

This is as close to non-destructive Punch and Roll editing that you can get in Audacity. Since the script relies mostly on shortcuts built into Audacity, it should be easy to port to other operating systems (like Linux or Windows).

This script above assumes that you have 2 Audio tracks and a Label track set up in your Audacity Project (see below). Feel free to download my VO Project Template for Audacity.

audacity-template

To use this script on OSX, either paste it into AppleScript Editor and save it as a program, or use Automator to Create a Service (pictured below).

audacity-automator

The advantage of using a Service is that you can assign it a Keyboard Shortcut in System Preferences (see below).

audacity-services-preferences

Once you’ve tried it, let me know what you think πŸ™‚

A Cup of Coffee

A ridiculous amount of caffeine was consumed while researching all of this stuff.
Add some fuel if you would like to help keep me going!
$5$10$15$20$25Other

23 thoughts on “Punch and Roll editing in Audacity on Mac OSX

  1. Hi Steve,
    Thanks for creating this script. I’ve entered it into a “Run AppleScript” service in Automator, but upon keyboard shortcutting it in Audacity, I get an error message. Do I need the beginning and ending script lines that Automator provides to bracket the script you wrote? These are as follows:
    on run {input, parameters}
    ( *your script goes here* )
    end run

    I’ve tried your script with and without the provided “on run” and “end run” lines, with errors both times. I’ve selected Audacity for the “in” dropdown menu, and “no input” for the “services receives” dropdown menu, as illustrated in your post. Thanks for any suggestions!

    1. Hi April! Sorry for the delay in getting back to you. You should remove the sample text provided by Automator. When you have it typed out exactly as listed above, press the Hammer Icon and Automator will compile your script. There should be no errors. If you still encounter problems, let me know.

  2. Steve, thanks for your reply. Success! I followed your instructions, then figured out that in my OS, a space is required between the words in “end tell” in order for Automator to compile the script. Now it’s working like the champ you created it to be. Yahoo! Thanks once again.

  3. Steven, I can’t thank you enough for doing this but I have what I hope is a quick question. I’ve entered the script as a service as you suggested and assigned the short cut. I place my cursor and key in the short cut but what I get is the waveform from the cursor to the end of the recording highlighted (Good!) I get a label (Good!) But then in the label is [,,,,, AR] without the square brackets. It also doesn’t give me playback or start recording. I’m running macbook air with 10.9.4 if that makes any difference? Any ideas? I’d love to be able to use this.

    1. Hi LC. It sounds like you may have miss-typed the script, or that you are not using the template file that I link to in the posting (the script assumes that you are using my template). Are you using my template? If so, does the script work when you activate it manually (without the service)?

  4. Hi Steve,

    Thanks for assuming I can figure this out. I saw your note about AHK, and have been trying to figure out how to use it. But the tutorial is making my head explode. I can’t tell if I can just copy and past your script or if I’m supposed to make changes or if I need to add anything.

    Ruth

    1. My AppleScript will not work directly in AutoHotKeys. But, since each of my lines is explaining what it is doing, you should be able to build it on your own in AHK. Try out my script first on a Mac to get a better understanding of what it is doing. Or, do each of the steps described on your own in Audacity. Then, you will truly understand the script.

  5. Thanks for this! Tons of help just learning the syntax to automate synchronization of video and audio streams for recording behavioral trials for my research!

    Cheers,
    Matt

  6. Hi Steve, thanks for the script !
    I have tried it on version 2.1.1 but it seems it does not back up the 5 seconds (the “,,,,,” part).
    Any idea on how to correct it ???

    Thanks Again

  7. Just to let you know that after much fiddling, I solved the problem of the script not backing up before playback/recording by changing the keystroke “,,,,,” instruction with 5 key code 43
    In case some other user may experience the same situation.

    Thanks again

  8. Steven,
    Thanks! Works great other than the delay caused by the script but I don’t think there will be a way around that until Audacity builds it in.

    1. Agreed Dan. I’ve spoken with some of the Audacity developers about including their own built-in scripting method. That seems a lot easier on their end than implementing the features that we are implementing here. Also, that would mean a script like this would work in Audacity everywhere, not just on the Mac.

  9. Steven,
    I just want to say THANK YOU for this! This is the (almost) perfect solution for me.
    My long-form narration is going So Much more smoothly since I put this script in my Mac. I must say that I’m shocked that this isn’t more widely known as THE punch & roll solution for Audacity. It works great for me.
    Actually, I found that an even simpler script – cutting only, with no paste – works best for my needs. I don’t need to be ‘non-destructive.’
    Again – Thank You!

Leave a Reply

Your email address will not be published. Required fields are marked *