I don't think MSLayer
stores a direct reference to its shared style (or I couldn't find one with a quick look).
Instead, there is layer.style().sharedObjectID()
, which you then need to look up in the document styles.
var layer = context.selection.firstObject();
var sharedStyleID = layer.style().sharedObjectID();
var name = null;
if(sharedStyleID){
var textStyles = context.document.documentData().layerStyles().sharedStyles();
for(var i = 0 ; i < textStyles.length; ++i){
if(String(textStyles[i].objectID()) === String(sharedStyleID)){
name = textStyles[i].name();
}
}
}
log(name);