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:

#!/bin/sh
for file in /Users/RamiroLaptop/Desktop/03-TTFAutohint/*
do
  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

done

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.
 

Comments

  • Khaled HosnyKhaled Hosny Posts: 181
    Try this, to be use as script.sh path/to/font/dir/:
    #!/bin/sh

    pushd $1
    mkdir -p Hinted-Fonts

    for file in *
    do
    ttfautohint -v -f latn -n -w G "$file" Hinted-Fonts/"$file"
    done

  • Ramiro EspinozaRamiro Espinoza Posts: 559
    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:
    The following error occurred while opening font `/Users/RamiroLaptop/Desktop/03-TTFAutohint/Hinted-Fonts//Users/RamiroLaptop/Desktop/03-TTFAutohint/LaskiSans-RegularItalic.ttf':
     No such file or directory

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


  • Khaled HosnyKhaled Hosny Posts: 181
    Just replace $1 with the path you want.
  • Ramiro EspinozaRamiro Espinoza Posts: 559
    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
    ...
    fi

     this allows your script to do ttc and dfont, for example. Items not ending with ttf.
  • Khaled HosnyKhaled Hosny Posts: 181
    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.