Hey!
I am tinkering a bit with the code from the “remote scripts” folder in the Glyphs SDK repository.
I am trying to export some instances from a .glyphs file with this script:
import os
import time
from Foundation import NSURL, NSConnection, NSObject # type: ignore
def application(appName, port=None):
if port is None:
port = "com.GeorgSeifert.Glyphs3"
conn = None
tries = 0
while (conn is None) and (tries < 10):
conn = NSConnection.connectionWithRegisteredName_host_(port, None)
tries = tries + 1
if not conn:
time.sleep(1)
if not conn:
print("Could not find a JSTalk connection to " + appName)
return None
return conn.rootProxy()
class GSStdOut(NSObject):
def setWrite_(self, text):
print(text, end="")
def setWriteError_(self, text):
print(text, end="")
def export_instances():
"""
This will export all instances of the font at 'path' as TrueType fonts.
"""
path = os.path.expanduser("~/Desktop/test/font_name.glyphs")
doc = Glyphs.openDocumentWithContentsOfFile_display_(path, False) # type: ignore
print("Exporting:", doc.displayName())
font = doc.font()
for instance in font.instances():
print("Instance:", instance)
instance.generate_(
{
"ExportFormat": "TTF",
"ExportContainer": "woff",
"Destination": NSURL.fileURLWithPath_(
os.path.expanduser("~/Desktop/test/")
),
}
)
doc.close()
print("Ready!")
if __name__ == "__main__":
Glyphs = application("Glyphs")
GSApplication = Glyphs
if Glyphs and Glyphs.orderedDocuments():
currentDocument = Glyphs.orderedDocuments()[0]
else:
currentDocument = None
export_instances()
I get this output in the terminal
Exporting: font_name.glyphs
Instance: <GSInstance 0x600006674f00> Regular (100.0, 100.0, 0.0, 0.0)
Instance: <GSInstance 0x6000066770c0> Thin (70.0, 49.0, 0.0, 100.0) (Contrast Thin)
Instance: <GSInstance 0x600006675440> Light (70.0, 73.0, 0.0, 100.0) (Contrast Light)
Instance: <GSInstance 0x600006677900> Regular (70.0, 98.0, 0.0, 100.0) (Contrast Regular)
Instance: <GSInstance 0x600006677600> Medium (70.0, 120.0, 0.0, 100.0) (Contrast Medium)
Instance: <GSInstance 0x600006676580> Bold (70.0, 156.0, 0.0, 100.0) (Contrast Bold)
Instance: <GSInstance 0x600006677480> Heavy (70.0, 190.0, 0.0, 100.0) (Contrast Heavy)
Instance: <GSInstance 0x600006675ec0> Black (70.0, 228.0, 0.0, 100.0) (Contrast Black)
Instance: <GSInstance 0x600006676f40> Ultra (70.0, 279.0, 0.0, 100.0) (Contrast Ultra)
Ready!
but no export in Desktop/test. Any clue?