I'm using Composer's Desktop Project to edit audio files and want to apply the same command to a whole set of WAV files instead of entering it manually for each one. For a single 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 command or loop that can process every WAV file in the current folder without listing each filename in a script?
2 Answers
Another readable version is to remove the `.wav` extension first, then add the output suffix: `for input in *.wav; do base="${input%.wav}"; distort average "$input" "${base}output.wav"; done` Make sure the `distort` command is available in your PATH, or use its full path. This works in both Bash and Zsh, which are commonly available on macOS.
A shell `for` loop can run the command once for every WAV file. From the folder containing the files, try: `for f in *.wav; do distort average "$f" "${f%.wav}output.wav"; done` This keeps the original filename and creates an output such as `soundfileoutput.wav`. The quotes also help protect filenames that contain spaces.

If you save the loop in a script, you can start it with `#!/usr/bin/env bash` and make it executable with `chmod u+x scriptname`. Also be careful not to run it repeatedly in the same folder unless you change the file pattern, since generated output files may otherwise be processed again.