My goal is to be able to select a layer and run the script to ensure the fontFamily is correct - of course this is to later ensure other properties of the text layer is correct.
My issue is - every time I try to get the property to compare, I get thrown back some layer hexcode in the log, and the alert messages say font is undefined.
var onRun = function(context) {
//reference the Sketch Document
var doc = context.document;
var selection = context.selection;
if(selection.count() == 0) {
doc.showMessage("Please select something.");
} else {
for(var i = 0; i < selection.count(); i++) {
if(selection[i].class() == "MSTextLayer") {
var textLayer = selection[i].style;
log(selection[i].style().fontFamily);
var fontStyle = textLayer.fontFamily;
if(fontStyle == "Open Sans") {
var alertM = "Correct! The font is " + fontStyle;
alert("Layer check", alertM);
} else {
var alertM = "Nope! The font is " + fontStyle;
alert("Layer check", alertM);
}
} else {
doc.showMessage("Please select a layer to check.");
}
}
}
}
Code sample above. Please advise on how to fix 🙂