Troubleshooting when a script stops working

Hi there —

I recently ran into a problem with the Alex Slobzheninov collection of scripts that I use on a daily basis when, all of the sudden, they stopped working (I run the script but nothing happens). I’m not a developer or coder but know enough to check the macro panel after attempting to run a script unsuccessfully and receive an error message of the following:

Traceback (most recent call last):
  File "Align", line 298
    cpsPressed = NSEvent.modifierFlags() & cpsKeyFlag == cpsKeyFlag
NameError: name 'NSEvent' is not defined

I’ve never had any issues with running this collection of scripts until a few days ago but didn’t change any of my preferences, plugins, operating system, or anything at all that I can think of. I even attempted running the script in older versions of G3 that worked previously but was unable to find a version that worked anymore.

For someone like myself with very limited coding capability, what troubleshooting can be recommended to find the root cause & solution to a broken script like this?


Can you find the python file of that script? At the beginning of the script, can you add the following:

from Foundation import NSEvent

Ooops, sorry, I updated the scrips and missed that part. Thanks @SCarewe!
The update includes aligning any selection to the glyph metrics/center with Caps Lock on. Hit me up if you prefer the previous version.

Your suggestion worked!

After the very very beginning, I added your suggestion after the import NSPoint line:

DIRECTION = ‘Left’ # either ‘Left’ or ‘Right’
from math import radians, tan
from Foundation import NSPoint
from Foundation import NSEvent

@alexs Will you be updating your updates with this import NSEvent edit in the future? I trust you more than myselfl haha, but if the fix is as simple as adding the import NSEvent line I can just add that to the other python files and should be ok.

Thanks everyone for your help!

@JeremyNelson yes, missing it was an error. I corrected it, so now it doesn’t matter if you auto update it or add the line yourself :slight_smile:

Already updated them and everything is working again!

So does this mean that when you update the version/build of Glyphs you simultaneously get updates to any of the plugins and scripts you have installed through the Plugin Manager?

That would explain how the scripts were changed without me altering them personally and be helpful know about.

Either way, thanks again for the suggestions and help!