These scripts are helpful for tagging and tanscoding music. My most recently purchased Miho Wada album was a digital download of .wav files, so these scripts allowed me to:

  1. Convert the .wav files to .flac (for long-term storage)
  2. Convert the .wav files to .mp3 (for playback on my phone and computer)
  3. Attach album art to the .mp3 files

These automator workflows are also available on GitHub.

Convert to FLAC

First, install SoX command line tools via brew:

brew install sox

Then set up an Automator Service that receives "audio files" in "Finder.app". Use the shell "/bin/bash" and pass input "as arguments". Use the following code:

for f in "$@"
do 
  /usr/local/bin/sox "$f" "${f%.*}.flac"
done

Convert to MP3

First, install FFmpeg command line tools via brew:

brew install ffmpeg

Then set up an Automator Service that receives "audio files" in "Finder.app". Use the shell "/bin/bash" and pass input "as arguments". Use the following code:

for f in "$@"
do
  /usr/local/bin/ffmpeg -i "$f" \
    -vn -ar 44100 -ac 2 -ab 192k -f mp3 "${f%.*}.mp3"
done

Add cover from cover.jpg

First, install FFmpeg command line tools via brew:

brew install ffmpeg

Then set up an Automator Service that receives "audio files" in "Finder.app". Use the shell "/bin/bash" and pass input "as arguments". Use the following code:

for f in "$@"
do 
  dir=`dirname "$f"`
  /usr/local/bin/ffmpeg -i "$f" -i "$dir/cover.jpg" \
    -map 0:0 -map 1:0 -c copy -id3v2_version 3 \
    -metadata:s:v title="Album cover" \
    -metadata:s:v comment="Cover (front)" "${f%.*}.tmp.mp3"
  mv "${f%.*}.tmp.mp3" "$f"
done