thanks, I think editing the file in Sublime Text seems more practical for now.
Haven’t found a syntax highlighter for plist, but the AppleScript one seems to work fine so far.
import os
from Foundation import NSURL
thisFont = Glyphs.font
directory = "~/Desktop/" # trailing slash
for fileName in os.listdir(directory):
if fileName.endswith(".svg"):
# make note in macro window:
print("Importing %s" % fileName)
# check if the name complies:
if "-" in fileName:
glyphName, unicodeValue = fileName.replace(".svg","").split(":")[0:2]
unicodeValue = unicodeValue.replace("uni","")
# you may want to do a sanity check here and find out if
# unicodeValue really is 4 chars and only "0-F" etc.
else:
glyphName = fileName.replace(".svg","")
unicodeValue = None
# create the glyph and add it to the font:
newGlyph = GSGlyph(glyphName, autoName=False)
newGlyph.unicode = unicodeValue
thisFont.glyphs.append(newGlyph)
firstLayer = newGlyph.layers[0]
# for importing the SVG into the first layer, we need to convert
# the path into an NSURL, because the method requires it for input:
svgPath = directory+fileName
svgURL = NSURL.alloc().initFileURLWithPath_(svgPath)
firstLayer.importOutlinesFromURL_scale_error_(svgURL, 1.0, None)
Does the script work in Glyphs 2? or do I need Glyphs3?
In Glyphs 2 I’m getting this error in the Macro window:
Importing home-E002.svg
Traceback (most recent call last):
File "<macro>", line 23, in <module>
ValueError: need more than 1 value to unpack
thanks
Edit:
found this script one from a different thread,
There seems to be a minor bug, in that it doesn’t create the SVG layer, but is solved by manually creating a “svg” one, that fixes it, showing the placed SVG correctly.
as usual, thanks!