Create a new file via scripting

Is it possible? I thought of appending a new GSFont() object to GSApplication.fonts, but that apparently produces no result.

That is not in the wrapper, yet. For now you need to do this:

doc = Glyphs.documentController().openUntitledDocumentAndDisplay_error_(True, None)

I added it to the wrapper. With the next version you can then do:

font = GSFont()
Glyphs.fonts.append(font)
1 Like

Isn’t it just this?: Glyphs.newDocument()

Thanks! Glyphs.newDocument() did it.

Is it also possible to make a copy of the existing font?
(to have a backup if the script does not produce the desired result)

Just copy the font:

Backup = font.copy()

this creates a font object that has no interface. You can give it an interface:

Glyphs.fonts.append(Backup)

Ok, thanks.
I see what I did wrong…

Sigh.
Thought I got it, but it looks like there is another gap in my knowledge to fill up. Pasting next code in the Macro Panel

current_font = Glyphs.fonts[0]
print current_font
copied = font.copy()
Glyphs.fonts.append(copied)
copied.familyName = "Backup of %s"%copied.familyName
print copied
print Glyphs.fonts

does not go further than statement three: every time I use .copy() the next error appears:

Traceback (most recent call last):
  File "<string>", line 3, in <module>
ValueError: NSInvalidArgumentException - -[__NSCFString countByEnumeratingWithState:objects:count:]: unrecognized selector sent to instance 0x61800023dcc0

And the other discussed item,

font = GSFont("Name")
Glyphs.fonts.append(font)
print Glyphs.fonts

Does not show any new font, even not when printing a list of the fonts. Only Glyphs.newDocument() seems to make a new font for me. I guess I miss some insight in Python or the API, but which? All hints are welcome, thanks in advance

both scripts work fine for me. What version do you have?

I always work with the latest stable version.

Little correction on my previous post: the script I posted was accidentally an older version: The third statement should be copied = current_font.copy()

After your comment I tried both scripts on an other Mac. (One of my own that is not administered by the school). The first script does not produce an error, but no new interface window appears and the output in the console is not what is expected:

<GSFont "new Font" v1.0 with 1 masters and 0 instances>
<GSFont "Backup of new Font" v1.0 with 1 masters and 0 instances>
[<GSFont "new Font" v1.0 with 1 masters and 0 instances>]

(the new font should be in the latest list).

On the mac of school, Python 2.7 as wel as Python 3.0 is installed. On my own Mac, no additional software of which I think it can interfere with GlyphsApp is installed.

Now I tried also with the latest developer version.

Try the latest cutting edge version.

I tried that also.

The latest cutting edge version 2.1.1(787) produces the same error on the Mac from school, even after I installed Glyphs myself and not via the app ‘Managed Software update.’

I now also tried on my own Mac. The latest cutting edge sometimes duplicates the font (in a new visible window), but sometimes Glyphsapp crashes. I have send one of the bug reports with a link to this topic.

If I can do anything to track this bug, let me know.