Create a Quick Action to Convert Audio Files

December 15, 2024

Ever since I started making music, I’ve always needed to convert audio files between formats. Normally, I would simply save the file in the correct format to begin with but in some cases (*cough* Maschine *cough*), that option isn't always available.

My process until now has always been to use whatever I had available - If that meant opening the file in Adobe Audition, I'd do that. But ever since Adobe switched to a monthly subscription plan, I have had to resort to more time consuming ways like re-opening the file in FL Studio or using some ad-bloated online converter.

Here, I’ll walk you through the process of building a quick action in Automator.

Step 1 - Set up the foundation

First, make sure you have FFmpeg installed (if you haven’t already). FFmpeg is a powerful, free, and open-source tool for handling audio, video, and other multimedia files.

Simply use Homebrew to install it with the terminal command brew install ffmpeg.

Step 2 - Write the script

Next, open automator. When it launches, you'll be given a few options for the type of document you want to create. For our purposes, we can choose 'Quick Action'.

Change 'Workflow receives current' to 'audio files':

Descriptive image

In the search bar on the left, find the 'Run Shell Script' action.

Run shell script option

For 'Pass input:' choose the 'as arguments' option.

In the script window, replace the existing starter code with this:

for f in "$@"; do
    ext="${f##*.}"
    base="${f%.*}"
    ffmpeg -i "$f" "${base}.wav"
done

Note: To adjust what file type it converts to, change the line before 'done' to ffmpeg -i "$f" "${base}.mp3 or whatever file type you want. I created 2 separate quick actions because I'm exclusively converting between .wav and .mp3.

Next, save the file in your ~/Library/Services/ folder and give it a name like 'Convert to wav'.

Step 3 - Run the script

Find a file you want to convert, right-click it and find your script under the quick actions.

If you get an error like command not found: ffmpeg, it means Automator can’t find FFmpeg. You’ll need to specify the full path to FFmpeg in your script.

In terminal, run which ffmpeg. It will return the address of the command. For me it was at /usr/local/bin/ffmpeg

You'll want to adjust the automator script to:

for f in "$@"; do
    ext="${f##*.}"
    base="${f%.*}"
    /usr/local/bin/ffmpeg "$f" "${base}.wav"
done

Lastly, by default this converts the .mp3 to a bitrate of 128kpbs.

To change this, alter that last line again to read something like the below depending on your preferred Bitrate:

ffmpeg -i "$f" -ab 192k "${base}.mp3"

To understand what is going on, here is a quick breakdown:

  1. The code loops (for f in) through all the audio files passed into it as arguments ($@). f is a temporary variable representing each audio file.
  2. ext="${f##*.}": This extracts the file extension from f (the current file) and stores it in the ext variable.
  3. The base="${f%.*}" stores the file name in a variable without the extension.
  4. 1ffmpeg -i "$f" "${base}.wav"1 runs FFmpeg, takes the full path of the input file $f, and spits out a new file with the same name but a .wav extension (Don't ask me how this works 😅)

Hope you found this useful!


Profile picture

Hi - I'm Paul Matheson. Based in Seattle, WA Follow me on 𝕏.