This is my code
export function getLayerAttrColorSwatchName(attrObject: any, attr?: string) {
let swatchID = ‘’;
let swatchName = ‘’;
try {
if (attr === 'text') {
let textStyle = attrObject.sketchObject.textStyle();
let msColor = textStyle.attributes().MSAttributedStringColorAttribute;
swatchID = msColor.swatchID();
} else {
swatchID = attrObject.sketchObject.color().swatchID();
}
let swatches = context.document.sketchObject.documentData().allSwatches();
if (swatchID && swatches?.length > 0) {
let findSwatch = swatches.find((item) => String(swatchID) == String(item.objectID()));
if (findSwatch) {
swatchName = String(findSwatch.name());
}
}
} catch (error) {}
return swatchName;
}