© Norman Posselt (Monotype)

© Norman Posselt (Monotype)

More than a week ago, I was in Berlin leading a workshop on bash shell scripting at the TYPO Labs 2017 conference (get a run down of my workshop on the TYPO blog). Shell scripting definitely sounds mysterious and impenetrable if you’ve never indulged. However, it’s a relatively straightforward way (or it can be) of telling your computer what you’d like it to do in a text file rather than clicking around a GUI. What’s great about it is that even writing simple scripts, however inelegant they may be, can save you valuable time.

I started learning bash shell scripting by looking at other scripts that dealt with fonts. So, I’m posting the script we wrote in my workshop to help someone else get started.


The script: make-specimens.sh
The script takes a folder of TrueType fonts and creates an HTML webfont specimen for each one. The specimen is a pre-written HTML file that gets copied over into a specimen folder, along with other required files, and a find/replace is performed to insert the name of the font in the @font-face path. There is also an option to run the fonts through TTFAutohint, but it must be installed for that to work. There are instructions on how to run the script in the script itself (just open the file in a text editor) but they assume a small amount of knowledge.

Keep in mind the important thing isn’t necessarily what the script does, but the methods it presents — looping through fonts, using and modifying variables, or writing if statements, for example. They are useful beginnings.

Download the script and supporting files: Make-Specimens-Script.zip


Learning More
There are more shell scripting tutorials then you could possibly ever read. Here are some I’ve bookmarked at varying levels of depth:

Writing Shell Scripts
A quick guide to writing scripts using the bash shell
Shell Script Basics
Bash scripting quirks & safety tips


One Last Thing
In my workshop, I started by showing a script I wrote that packages our fonts — creating folders, putting the right fonts in the right folders, injecting a license into each one and finally zipping them all up. Here are lines for two important steps in that process:

One license for each folder

The line below copies a file into every folder in the working directory. It will not copy the file into subdirectories of those folders. Change <path to license file> to the path of the file you want to copy into each directory.

echo */ | xargs -n 1 cp -R -p <path to license file>

Zip each folder

This line zips every folder in the working directory and puts the zipped folders in a folder called ‘xFinalZips’. It will zip the ‘xFinalZips’ folder too but who cares, just delete it! You have to create the ‘xFinalZips’ folder for this to work, so that’s what the mkdir line does. The folder name can be changed to anything you want, of course.

mkdir xFinalZips
find . -type d -d 1 -exec zip -r xFinalZips/{} {} \;

Happy scripting! — Nicole