Mac OSX Terminal – Bash – Convert MP3 to M4R (iPhone Ringtone)

| | | |

If you have an MP3 that you’d like to use for your iPhone the script below will help you get that file into your ringtone options.

#!/bin/sh

#  ConvertMP3_To_iPhone.sh
#
#
#  Created by David Kittell on 4/30/18.
#

DIR=$1

mkdir -p $DIR/iPhone

cd $DIR
for f in *.mp3
do
  filename="$(basename -- "$f")"
  extension="${filename##*.}"
  filename="${filename%.*}"
  afconvert "$f" -o "iPhone/$filename.m4r" -f m4af -d aac
done
sh ConvertMP3_To_iPhone.sh /Users/MyUser/Desktop/sounds

Then you can copy the .m4r files into iTunes Tones directory/screen and sync with your phone.

All information on this site is shared with the intention to help. Before any source code or program is ran on a production (non-development) system it is suggested you test it and fully understand what it is doing not just what it appears it is doing. I accept no responsibility for any damage you may do with this code.