Saving .glyphspackage with Font.save() broken

Hello, for some reason, running the following code doesn’t work anymore in 3117:

Font.save(Font.filePath, Font.familyName + ".glyphs")

It returns “file type must be .glyphs or .ufo”. This did not happen before. Converting the original file to .glyphs and running the same code works. Is this intentional?

Ok, even on .glyphs files it’s broken:
Font.save(path="/Users/sebastiancarewe/Desktop")

returns:
Save file must have file extension .glyphs or .ufo

This used to work in 3116. Honestly, I really need this to work, as I need to create 21 derivative glyphs files rather urgently.

You can always use the underlying ObjcC API. Have a look at the implementation of the python wrapper (in the GlyphsSDK repo).

URL = NSURL.fileURLWithPath_(path)
if path.endswith('.glyphs'):
	typeName = "com.schriftgestaltung.glyphs"
elif path.endswith('.glyphspackage'):
	typeName = "com.glyphsapp.glyphspackage"
font.saveToURL_type_error_(URL, typeName, None)

I fixed the .save() method.

1 Like

The world would be a better place if every developer responded as promptly as you.

Any chance of knowing when the fix will be published? I have a pretty extensive script that I am not very keen on re-writing which uses Font.save() a lot.

Rewriting would overstate it. You need to change one line:

Font.save(path)

to

Font.saveToURL_type_error_(NSURL.fileURLWithPath_(path), "com.glyphsapp.glyphspackage", None)

Ah, I didn’t know it all fit into one line. Thanks a lot!

Does this also work if I want to save it under a different name? My current Font.save() works with a custom name for each file.

It will be saved to whatever file name is in “path”. With this method, you need to supply a path. It will not get the existing one from the document.

Hello, I am getting ValueError: depythonifying 'unsigned char', got 'str' if I pass my file location as an argument. How do I pass the argument correctly?

Can you put the carton creation of the URL into its own line so see where exactly the error occurs? And how do you set the path?

I want to save the file under the current family name in a different folder (original save folder + “/OTVAR/Glyphs files”)

filename = self.font.filepath.replace(self.font.filepath.split("/")[-1], "OTVAR/Glyphs files/" + self.font.familyName)
Glyphs.currentDocument.font.saveToURL_type_error_(NSURL.fileURLWithPath_(filename), "com.glyphsapp.glyphspackage", None)

In what line is the problem?

When I call the method saveToURL_type_error_().

Are you sure it is not the NSURL part?

I’m afraid I don’t know what that is.

Do you mean I should first call the method NSURL.fileURLWithPath_()? I think I understand your previous message now.

Okay, now I really don’t understand what I’m doing wrong:

NS_url = NSURL.fileURLWithPath_(Font.filepath)
Glyphs.currentDocument.font.saveToURL_type_error_(NSURL.fileURLWithPath_(NS_url), "com.glyphsapp.glyphspackage", None)

Returns:

ValueError: NSInvalidArgumentException - -[NSURL length]: unrecognized selector sent to instance 0x6000f0abb480

You put a NSURL inside an NSURL. Use this instead:

NS_url = NSURL.fileURLWithPath_(Font.filepath)
Glyphs.currentDocument.font.saveToURL_type_error_(NS_url, "com.glyphsapp.glyphspackage", None)

I am very stupid. Of course, thanks.

But now, I get the initial error:

ValueError: depythonifying 'unsigned char', got 'str'

On what line do you get this??? Without context, we can’t help.

This is literally all he context there is. I run exactly these two lines of code:

NS_url = NSURL.fileURLWithPath_(Font.filepath)
Glyphs.currentDocument.font.saveToURL_type_error_(NS_url, "com.glyphsapp.glyphspackage", None)

Macro panel gives the following:

Traceback (most recent call last):
  File "<macro panel>", line 2
ValueError: depythonifying 'unsigned char', got 'str'

So it is when I call the method Font.saveToURL_type_error_().