Please help me with this shell script

Hi there,

I am trying to improve the coarse shell script I am using to use TTFAutohint in batch.

Currently I am doing:

for file in /Users/RamiroLaptop/Desktop/03-TTFAutohint/*
  ttfautohint -v -f latn -n -w G "$file" "$file-HINTED.ttf" 
  mkdir /Users/RamiroLaptop/Desktop/03-TTFAutohint/Hinted-Fonts
  mv /Users/RamiroLaptop/Desktop/03-TTFAutohint/*-HINTED.ttf /Users/RamiroLaptop/Desktop/03-TTFAutohint/Hinted-Fonts


But my method for saving the output is very clumsy: I am renaming the files and then moving them to a new directory.
I would like to just save the output in the new directory, but all my attempts have failed.
Can anyone help me with this? 
Thanks in advance.


  • Khaled HosnyKhaled Hosny Posts: 284
    Try this, to be use as path/to/font/dir/:
    #!/bin/sh<br><br>pushd $1<br>mkdir -p Hinted-Fonts<br><br>for file in *<br>do<br>  ttfautohint -v -f latn -n -w G "$file" Hinted-Fonts/"$file" <br>done

  • Ramiro EspinozaRamiro Espinoza Posts: 764
    edited July 2016
    The fact is I like to run it double clicking a .command file because I don't have to type anything. Can you add the output path inside the script? I've tried several combination but I always get:
    </code>The following error occurred while opening font `/Users/RamiroLaptop/Desktop/03-TTFAutohint/Hinted-Fonts//Users/RamiroLaptop/Desktop/03-TTFAutohint/LaskiSans-RegularItalic.ttf':
    <span style="font-family: 'Alright Sans from Webtype', 'Lucida Sans Unicode', 'Lucida Sans', 'Lucida Grande';"><pre class="CodeBlock"><code>&nbsp;No such file or directory

    Obviously I can't get the dynamic output address right. 

  • Khaled HosnyKhaled Hosny Posts: 284
    Just replace $1 with the path you want.
  • Ramiro EspinozaRamiro Espinoza Posts: 764
    edited July 2016
    Thanks! It works as a charm. I just modified the loop so it does not run on the folder:

    for file in *.ttf

  • You could test for an item being a file with 

    if [ -f $file ] then

     this allows your script to do ttc and dfont, for example. Items not ending with ttf.
  • Khaled HosnyKhaled Hosny Posts: 284
    I left the wild card as it was in your original script. @Hin-Tak Leung is good as well, or you can use a list of extensions *.{ttf,ttc,dfont} etc. though I don’t think ttfautohint handles all of these anyway.
Sign In or Register to comment.