Python scripts not working (807)

I have issues with running Python scripts. Ones that require saving and loading fail to do so, and I get lots of errors saying “global name ‘NSWhatever’ is not defined”.

I’m trying to get rid of the first delay when you run a script or start the app (80 % of the time is waiting on the python Bridge to load itself. The culprit is if you have from Foundation import * in your code. the first time you do that it takes 5-8 seconds. In Imports all of Cocoa and that takes a while. Now you need to import the things on your own. So add a from Foundation import NSWhatever, NSWhatelse, ... to the beginning of you script.

I don’t have import * (in fact I have never used it). Why do I suddenly need to import specific Cocoa modules? Is it going to be fixed?

The import * was done by Glyphs, I removed it to speed it up.

Could it be 807 needs to be restarted to reload scripts? I am trying to fix Tunnify but none of my changes seem to take effect when the script is re-run.

I keep getting the error message global name ‘NSMakePoint’ is not defined, even though I put in from Foundation import * at the beginning.

same here with the, but also with other scripts. An example error: global name 'NSClassFromString' is not defined

all including from Foundation import *

If you call a print NSWhatever after Foundation import * this printing line is properly executed. (while NSWhatever is the exact method that seem to be not defined as global name in the NameError. So it seems, that the method itself is at least properly imported and available. Or?

I just uploaded a new version that should fix most of the problems. If you use Cocoa classes in your script, you still need to import them yourself.

works like a charm again. thanks!

I cannot run help() in Macro window (help(GSGlyph) for example).

help() works again in 809.

from Foundation import *

for glyph in Glyphs.font.glyphs:
	print glyph.glyphInfo

Traceback (most recent call last):
File “”, line 4, in
File “/Users/georg/Programmierung/Glyphs/Glyphs/Glyphs/Scripts/”, line 2766, in
NameError: global name ‘GSGlyphsInfo’ is not defined

Script not working again in 815 and 816. Errors read like:
Nudge-move by Numerical Value Error: ‘LayerSelectionProxy’ object is not callable

And help() stopped working again.

We made Layer.selection a propert. So now you need to remove the parentheses in the script. Search for .selection() and replace with .selection

Okay that’s solved, but why has help(GSGlyph for example) has stopped again?

fixed it

now I got:

newFont = thisFont.interpolateInstance_error_( instance, None )
AttributeError: 'NSKVONotifying_GSFont' object has no attribute 'interpolateInstance_error_'

from Foundation import * is already in the script.

Version 2.2b (816)

I changed the method to:

- (GSFont*)generateInstance:(GSInstance*)Instance error:(NSError **)Error;
font.generateInstance_error_(Instance, None)

Please don’t do that. Only import what you really need. Otherwise you have to wait for several (6–8) seconds the first time you run a script.

Thanks. Works. And good point, I will change these import * later.