I'm using Composer's Desktop Project to edit audio files on macOS. I need to run the same command on a large batch of WAV files instead of entering it manually for each one. For one file, the command is `distort average soundfile.wav soundfileoutput.wav`, where `distort average` is the command, followed by the input and output filenames. Is there a Terminal loop or another simple way to process every WAV file in a folder without listing each filename in a script?
3 Answers
For a reusable script, put the loop in a file such as `process-audio.sh`, add `#!/usr/bin/env bash` at the top, and make it executable with `chmod u+x process-audio.sh`. Then run it from the folder containing the audio files. Test it on a few copies first so existing output files are not accidentally overwritten.
You can use a shell `for` loop. First change to the folder containing the WAV files, then run: `for f in *.wav; do distort average "$f" "${f%.wav}output.wav"; done`. This runs the command once for each WAV file, preserves filenames with spaces, and creates outputs such as `soundfileoutput.wav`.
The loop works in both Bash and Zsh, so it should work directly in macOS Terminal. `${f%.wav}` removes the `.wav` extension before adding `output.wav`. If the `distort` command is not found, make sure the program is installed and either available in your PATH or call it using its full path.

That’s exactly the kind of batch command I was looking for. Including `average` and quoting the filenames clears up the syntax.