From 392281cd49aa7b19b2431fc0f81cdf26c8cb8346 Mon Sep 17 00:00:00 2001 From: ivanholmes Date: Sun, 27 Dec 2015 21:51:39 +0000 Subject: [PATCH] Create renamefonts.py --- renamefonts.py | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 renamefonts.py diff --git a/renamefonts.py b/renamefonts.py new file mode 100644 index 0000000..8a80f1e --- /dev/null +++ b/renamefonts.py @@ -0,0 +1,55 @@ +#!/usr/bin/env python + +import sys, os, subprocess, copy + +if len(sys.argv) == 1: + print """ +usage: renamefonts.py + +This script requires FontTools/TTX to extract the font name from the font file itself, which is obviously highly important to the script's operation. + +You can rename as many font files as you like. Separate them with spaces only, not commas. On OS X, it's easiest to simply drag all your files into Terminal from the Finder. + +Font format can be ttf (TrueType), or otf (OpenType). FontTools/TTX apparently also works with Type 1 fonts, but I haven't tested this. +""" + +FNULL = open(os.devnull, 'w') + +TTFList = sys.argv +TTFList.remove(__file__) + +ConvertToTTX = [] +ConvertToTTX = copy.copy(TTFList) +ConvertToTTX.insert(0, 'ttx') + +try: + subprocess.call(ConvertToTTX, stdout=FNULL, stderr=subprocess.STDOUT) +except OSError as e: + print """ +This script requires FontTools/TTX to extract the font name from the font file itself, which is obviously highly important to the script's operation. + +Your system does not appear to have FontTools/TTX installed. +Check if it's installed, and if not, install it. +If it is installed, but the script still fails, check if it's added to the path. +""" +fileList = [os.path.splitext(i)[0] for i in TTFList] + +lookup = '