Maybe the problem lies in the last line. You should add a .copy() at the end, otherwise you are referencing that object directly, which is connected to the other font’s GSGlyph. But what you want is probably an unattached GSLayer so you can hang it on the GSGlyph in the new font without conflicts.
Bot scripts don’t do anything. You assigning a new object to a variable, that has no effect on the font where the layer that was assigned to that variable before.
This is how it could be done.
originFont = Glyphs.open("/Path/to/my/font", showInterface=False)
targetfont = Glyphs.font
if len(originFont.masters) != len(targetfont.masters):
raise "The master count doesn't match"
originGlyph = originFont.glyphs['A']
targinGlyph = targetfont.glyphs['A']
for idx in range(len(originFont.masters)):
originLayer = originGlyph.layers[idx]
targinGlyph.layers[idx] = originLayer.copy()
gfont = Glyphs.font
aGlyph = gfont.glyphs['A']
bGlyph = gfont.glyphs['B']
for layer in bGlyph.layers:
aGlyph.layers[layer.associatedMasterId] = layer.copy()