Export Masters to Subfolders

I was looking for a script that could export my instances into separate folders. Let’s assume I have a Thin, Regular, and Bold instance. And I want to export them to a structure like this:

FontName/Weight/*otf,*ttf,*woff2 …

That would mean I get 3 sub-folders inside the FontName folder with the respective font-files.

Right now I have to select each and every instance and font-file by hand and move them to those sub-folders (i need those to provide the different weights as downloads). I wasn’t able to find a script that would do that for me.

I’m working with glyphs 3 in a *.glyphs-file with 6 masters and about 20 instances defined in export.

Thanks a lot in advance for looking into it.

Export all files into one folder, change the path below to that folder, and it should do the trick:

import os, shutil
path = '/Users/UserName/Desktop/Fonts'

list_ = os.listdir(path)
for file_ in list_:
	name, ext = os.path.splitext(file_)
	if ext.lower() in ['.otf', '.ttf', '.woff', '.woff2', '.eot']:
		folder = path + '/' + name
		
		# create a folder
		if os.path.exists(folder) is False:
			os.makedirs(folder)
		
		# move the file to the folder
		shutil.move(path + '/' + file_, folder + '/' + file_)

Find the eweracs scripts in the plugin manager, they contain a script “Batch Export” which exports your instances into neat folders (ttf, otf, webfonts, etc)

No script required:
Add a custom parameter

"Export Folder" = "FontName/{{{weightClassUI}}}/{{{format}}}/"

in the font setting. If you need more control add one per instance.

3 Likes

I didn’t know about these tokens, that’s very cool. Where are they documented in the handbook?

I guess there’s no EOT anymore:

File "BatchExport.py", line 94, in __init__
    value=EOT in self.selected_formats["Web"]["Containers"])
          ^^^
NameError: name 'EOT' is not defined

Makes sense. I haven’t updated the script in years. I have since made my own export plugin that replicates this script’s behaviour, with a lot more export options.

This is great and sorry for not checking in for so long after I initially asked.

I tried copying {{{weightClassUI}}} but it exports it as a literal folder not as a variable. Not sure if I got this wrong. The other solution would probably be, to create an “Export Folder” for each instance.

What version of Glyphs do you have? You might need to get the cutting edge version to get it to work.

I have version 3.2.3 (3260) installed.

This is how I have set it up under Font Info/Font. I select the font name folder by hand, when exporting. Do I need to activate something else?

Can you try on the latest beta? You can install it by checking the “show cutting edge versions” in your Updates preferences of Glyphs.

Don’t worry, you can revert to the older version or even have multiple versions installed alongside one another.

Think I should add this: Thank you all. You are always so quick to reply and are so well informed. Really thankful for all the help I found in this forum.

I updated to the cutting edge version. It works in part. {{{weightClassUI}}}/{{{format}}} Creates a folder for the first weight and exports all other weights to the same folder. Format works though. It creates a new folders for each font format. I wonder if I might need a different variable or if there is something else going on. Can I find the various possible variables somewhere?

Just to check, have you set the weight class differently for each instance? Or are they all set to 400: Regular?

For the one I tested it with no. I checked with another one, where I set different weights. There it worked. Thanks for pointing that out.

Still, I have two axis in the large font—one for weight and one for serif/sans. I would need to write a different variable I guess. Is there some kind of list, so I could customize the variable? Ideally I would like to use “Style Name” as a variable.

You can use all kinds of things in those tokens. try: {{{name}}}.

This works perfectly, and will make exporting and sorting so much easier in the future.
To get the folder structure I needed I used {{{familyName}}} {{{name}}} to get “Fontname Exported Weight” as a result. Thanks a lot to everyone who helped. Have a nice holiday and a happy new year.