Mac OSX Terminal – Rename TTF/OTF Fonts

If you have ever received a list of fonts from a client where the font names didn’t make sense this code below will help.

Caution: Backup your fonts directory just in case.


#  Created by David Kittell on 1/18/18.
# Use script like "sh ~/Desktop/fonts/"

# Prerequisite
#brew install fontconfig

#for f in * ; do
#  mv "$f" "$f.ttf"

if [ -z ${1+x} ]; then
  printf "\033[01m\e[4mType your desired font directory, followed by [ENTER]:\n\e[0m\033[0m"
  read ftDir

printf "\033[36mSearch Directory:\033[0m %s \e[90m$ftDir\033[0m\n";

for file in "$ftDir"*.{ttf,otf,TTF,OTF}; do
  postscriptname=$(fc-scan --format "%{postscriptname}\n" $file);

  if [ ! -z "$postscriptname" ]; then
    printf "\033[36m PostScript Name:\033[0m %s \e[90m(%s)\033[0m\n" "$postscriptname" "$file";
    mv "$file" "$ftDir/$postscriptname.${file##*.}"

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.