Saving a font as UFO via script

Is it possible to save a font as UFO via script? I tried font.save(‘myfont.ufo’) but it resulted in a Glyphs file.

That is not in the wrapper so the code is not very nice:

ufoExporter = Glyphs.objectWithClassName_("GlyphsFileFormatUFO")
ufoExporter.setConvertNames_(True) # if you need production names.
ufoExporter.setFontMaster_(font.masters[0])
url = NSURL.fileURLWithPath_("path/to/file.ufo")
ufoExporter.writeUfo_toURL_error_(font, url, None)
1 Like

Thanks! Works like a charm, just what I needed.

For reference, here is my complete script:

#MenuTitle: Save UFO as copy
# encoding: utf-8

from GlyphsApp import *

doc = Glyphs.currentDocument
font = doc.font

ufoExporter = Glyphs.objectWithClassName_("GlyphsFileFormatUFO")
# ufoExporter.setConvertNames_(True) # if you need production names.
ufoExporter.setFontMaster_(font.masters[0])
url = NSURL.fileURLWithPath_( os.path.splitext( font.filepath )[0]+'.ufo' )
ufoExporter.writeUfo_toURL_error_(font, url, None)
3 Likes