Skip to content

Instantly share code, notes, and snippets.

@retrography
Last active April 15, 2017 13:33
Show Gist options
  • Save retrography/8da73ae460e11597fa7c to your computer and use it in GitHub Desktop.
Save retrography/8da73ae460e11597fa7c to your computer and use it in GitHub Desktop.
A simple shell script that converts audio files into Apple Lossless (ALAC) format. It can be used to create an Automator service on MacOSX. Requires brew, ffmpeg, coreutils, AtomicParsley and rmtrash.

Instructions

  • Install requirements using brew

Requires ffmpeg, coreutils, AtomicParsley and rmtrash If you don't have brew:

xcode-select --install
ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"

Then install the required packages:

brew install ffmpeg coreutils AtomicParsley rmtrash
  • Create audio2alac OSX service
  1. In Automator create a service for audio files and set it to run a shell script

  2. Set "Pass input:" to "As arguments" and then replace the auto-generated shell script with the one above

  3. Save the service with a name you like (e.g. audio2alac)

A new service should show up on the context menu when right-clicking audio files in finder.

#!/bin/zsh
# Simple shell script to make a "audio2flac" automator workflow
# Copyright © 2014 Mahmood S. Zargar
for f in "$@"
do
abspath=$(greadlink -fn "${f}")
dirname="${abspath%/*}"
filename="${abspath%%.*}.m4a"
export PIC_OPTIONS="removeTempPix"
if [[ "${abspath}" == "${filename}" ]]; then exit 1; fi
if ffmpeg -i "${abspath}" -y -acodec alac "${filename}"; then
ffmpeg -i "${abspath}" -y -loglevel quiet -an -vcodec copy "${dirname}/000cover000.jpg" || :
AtomicParsley "${filename}" --artwork "${dirname}"/*.(jpg|png) --overWrite || :
rmtrash "${dirname}/000cover000.jpg" || :
# Send to original to Trash after successful conversion
# rmtrash "${abspath}" || :
else exit 1
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment