Is it possible to script selecting a range of glyphs based on a provided list in Glyphs? I’m working on some automations and I’ve got a defined list of glyphs that I’d like to be able to perform an action on but haven’t seen if there’s a way to use python to select them.
I already have something working based on manually selecting glyphs and checking with Glyphs.font.selection but am not sure if there’s an API to have Python do the select action for me.
Thanks Mark and Sebastian. For some reason I’ve had it stuck in my head that the script needs to actually have glyphs selected to then do something but of course you’re right and there’s an easier way. Appreciate the nudge to unstick my brain!
You’re not wrong – a script can also use the glyphs currently selected in font view (or edit view). Have a look at the Font.selectedLayers property. This is useful when you want to run a script on selected glyphs again and again, but for differing selections.
In the event this is useful to anyone, I ended up figuring how to do what I originally inquired about to support a demo of the real tool I initially thought I needed this for. I wish I could share more about exactly what I was building but… pesky NDAs (hint: it involves type — and laser projection directly from Glyphs).
Anyway, the way to do this is very simple:
from GlyphsApp import *
Glyphs.clearLog()
# Unicode for glyphs to select
glyphsList = [
'1F318',
'1F64F',
'1F49A',
'1F600',
'1F60D',
]
if Font:
# clear any existing selected layers
Font.selection = []
newList = []
for myGlyph in glyphsList:
newList.append(Font.glyphs[myGlyph])
Font.selection = newList
else:
print("No font open in Glyphs.")