Update Glyphs file after editing content from script

Hi!

I used to open a Glyphs file in a text editor when I wanted to do a search and replace, for example to quickly change instances names, or basically anything that is longer to change with the UI.
I ended up writing a script that let me search and replace from Glyphs directly.

Because I want to easily access all data at the same time, I’m using open(), read(), write() etc so I effectively do the exact same thing as opening the file in a text editor.
The thing is that my opened Glyphs file doesn’t update with the new data written from the script. I have to manually close and open the file again to see the changes.

I guess I could add something to close and reopen automatically, but that doesn’t seem clean.
Is there a way to kind of refresh the view of the Glyphs file so that it shows the actual data that has just been written into it?

First, I would try to change the data objects. Changing instance names is easier when accessing the names directly. The only thing I do in the text file is to change the fontMasterId. That is tedious in the API because it is used in different places.

If you still like to edit the file, have a look at NSDocument.revertDocumentToSaved_(sender)

I gave instance names as an exemple but I want to be able to search everywhere, custom parameters, the Font fields etc… it seemed more straightforward to open and write in the file than having to iterate through each kind of objects I want to modify.
Unless it’s really unsafe to do it that way, I will look into that method you mentioned.
Thanks Georg!