Hi! I’m on Sketch 2025.2.1 (Barcelona) and I’m trying write plugin code for getting and setting the text in TextLayers, for localization purposes. I’ve got that working fine, but now I also need to get/set the internal styling (mainly bold/italic and color) of individual text-ranges inside a string.
I’ve found out that string-internal styling is stored as attributedString with attributes in the Sketch (JSON) Open File Format, but I’m looking for a way to access this data from JavaScript code.
A sketch.Types.Text layer does not seem to have direct access to this data. But I can use layer.sketchObject to get the underlying native MSTextLayer object, and from that I can use .attributedString() to get the MSAttributedText object, which also gives me the text-string via its method .string().
However, then I’m stuck, since from there I don’t know how to access the array of stringAttribute (?) objects which I suppose contain attributes of type MSAttributedStringFontAttribute and MSAttributedStringFontColorAttribute etc.
Any help would be appreciated.