Script help: removing "=="

Through some sequence of update corruption or user error, I have many glyphs that have their sidebearings set to “==n” (where n is some other glyph). This is the proper setting when you want to borrow sidebearings from another glyph for this master only, but somehow I have that happening in a bunch of sidebearings where every master borrows those settings. In other words, light and regular /copyright LSBs will be O, but bold will be ==O. Or light and bold /rightarrow LSBs will be =|leftarrow, but reg will be ==|leftarrow.

What’s the easiest way to clean this stuff up–to remove extraneous equals signs when all masters’ sidebearings make the same reference?

Scripting, as far as I now. This deletes layer-specific keys of selected glyph. It does not report which glyphs had those, but can modify that way if you want:

for layer in Glyphs.font.selectedLayers:
	g = layer.parent
	for l in g.layers:
		if l.leftMetricsKeyUI()[:2] == "==":
			l.setLeftMetricsKeyUI_(None)
		if l.widthMetricsKeyUI()[:2] == "==":
			l.setWidthMetricsKeyUI_(None)
		if l.rightMetricsKeyUI()[:2] == "==":
			l.setRightMetricsKeyUI_(None)

Should this work by pasting it into the top of the Macro window and hitting Run? I get this:

  File "<string>", line 1, in <module>
AttributeError: 'NSKVONotifying_GSFont' object has no attribute 'selectedlayers'

Oh sorry, it should be “selectedLayers” (L is uppercase).

Now I get

  File "<string>", line 1, in <module>
AttributeError: '__NSArrayI' object has no attribute 'parent'

Sorry again. I edited the code above, so please try it.

Yes, (once I again capitalized the “l”) that seemed to work. Thanks! I appreciate the help.
Would it be far more complicated to build in a test that checked whether all masters had the same key setting before removing the equals signs? I can imagine that being a more broadly useful script–kind of akin to the “Clean Up Kerning” function that determines which kerning settings are extraneous and deletes those that are.

I have the script already. It’s called Report Metric keys and checks three things: nested keys, layer-specific keys, and invalid keys (which now G2.3 detects as default).

Fantastic stuff. Thanks again!

Georg already has a script Helper > Remove Layer-Specific Metric Keys that does almost exactly that.

2 Likes

Thanks, I didn’t notice that (was expecting that under Metrics&Classes folder if there was one).