Glyph name swap script problem

I’ve got a script I’ve been using for years for making “alt” versions of fonts. It swaps glyph names between default and alternate glyphs, among other things. It’s been working fine for some fonts (Proxima Nova is the one I use it with most often), but it’s not working right for others.

Here’s what the main swap code looks like:

font = Glyphs.font
for g1Name in swapList.keys():
    g2Name = swapList[g1Name]     # second item
    print g1Name, g2Name
    g1 = font.glyphs[g1Name]
    g2 = font.glyphs[g2Name] = "temp" = g2Name = g1Name

(swapList is a dictionary loaded from one or more external text files containing a pair of glyph names on each line.)

The font it’s not working in has 6 masters. When I run the script, composite glyphs are not modified consistently between masters, so I end up with glyphs getting swapped in some masters but not others. For example, this is after running the script:

In the above screenshot, the accented characters should match the base character (which has been correctly swapped) in each of these sets of five characters, but they don’t. It’s a complete mess. I could manually fix each character, but the whole point of the script was to do it all automatically.

Has something changed in the way renaming glyphs works? This script worked flawlessly the last time I used it (about three years ago). I use the same script (except for the swap data) with Proxima Nova, and it still works fine.

Note: I’m seeing this issue in Glyphs version 2.6.2 (1268).

Try using the cutting edge version See: Scripts stopped working in 2.6.2, started again in 2.6.3

Thanks, Dave. I’ll give that a try.

Are you swapping the names of the compounds too?

You could use the custom parameter “Rename Glyphs” on the alternate instances. Then you wouldn’t need the script at all.

I’m wondering why it works for some masters – it shouldn’t. Components are linked to the glyph itself and not to the name. So you need to update the components, too. But the suggestion from @jkutilek is probably the better solution.

Hi Georg,
I wrote to you about this a while back, I ran into the same issue. I have a script that does basically the same thing:

source = [x.strip() for x in self.w.source.get().split(" ")]
target = [y.strip() for y in" ")]
tempSource = [str(s)+".temp" for s in source]
def changeNames(sourceList, targetList):
	for x in range(len(sourceList)):
		glyph = Font.glyphs[sourceList[x]] = str(targetList[x])

changeNames(source, tempSource)
changeNames(target, source)
changeNames(tempSource, target)

I am including composite glyphs in the input lists, and have varying results: it sometimes work, sometimes not, even on the same glyphs file.

About the Rename Glyphs parameter, I also posted about this: it can only be used if you expect kerning groups to be the same between the two swapped glyphs. It was not an acceptable solution for me which is why I wrote the script in the first place.

I am swapping the names of the component glyphs also.

The results differ depending on which master is active in the font view as well. The component glyphs are swapped correctly for the active master and zero, one or two other masters, and component glyphs the rest of the masters are not swapped. Which masters are swapped correctly is not always the same, except for the active master.

The Rename Glyphs isn’t suitable for the reason @joachimvu mentioned regarding kerning groups.

@mekkablue at some point, you helped me with this script. I think that’s how font.disableUpdateInterface() got in it, although I think you helped with other parts of the snippet above.

In any case, whatever was going on, switching to the latest cutting edge version fixed the issue. ¯_(ツ)_/¯ The script runs correctly now.

I just tested this. And component and classes are working fine.
This is what I have:

I have two instances. One has Rename Glyphs parameter:
T and Tcaron are in one class as are T.ss01 and Tcaron.ss01.


In indesign I typed AT AŤ AT AŤ:

  1. Myriad
  2. Regular instane
  3. Instance with rename parameter
  4. Regular instance with disabled kerning.

Okay, thanks. I will look into using the Rename Glyphs parameter in the future. For now, since my script is working in the latest cutting edge version, it will be simpler to keep using it.

I spoke too soon. The problem persists even in the latest cutting edge version, but sometimes it works.

If I run the script and it fails to make the swaps correctly, I’ve found that (sometimes) if I revert the font and reload scripts and try again, it will eventually work correctly. Sometimes I have to do this more than once before it works. I’m not totally sure reloading scripts is necessary, except that I’ve done that all the times when it worked correctly, as far as I can recall.

But sometimes it still doesn’t work at all. I have four scripts I use with this font (four alt versions). Two of them eventually work and two of them don’t. The scripts are identical, except for which glyph lists they load from text files.

For now I guess I will manually fix the two fonts where it doesn’t work correctly since they (luckily) don’t have as many glyphs that need to be swapped.

I didn’t try this yet but it might help to scroll past all components in font view for each master before you run the script. You need to have seen all glyphs…

Ah! That seems to work. Thanks!