For text you can check if a swatch ID exists
let sketch = require('sketch')
let doc = sketch.getSelectedDocument()
let selection = doc.selectedLayers.layers[0]
let textStyle = selection.style.sketchObject.textStyle()
let mscolor = textStyle.attributes().MSAttributedStringColorAttribute
if (mscolor.swatchID()) {
// it's a color variable
}
likewise you can do something similar for a shape fill
let fill = selection.style.fills[0]
let mscolor = fill.sketchObject.color()
if (mscolor.swatchID()) {
// it's a color variable
}
So putting it all together you can do this
let sketch = require('sketch')
let doc = sketch.getSelectedDocument()
let selection = doc.selectedLayers.layers[0]
let mscolor
if (selection.type === 'Text') {
let textStyle = selection.style.sketchObject.textStyle()
mscolor = textStyle.attributes().MSAttributedStringColorAttribute
} else {
let fill = selection.style.fills[0]
mscolor = fill.sketchObject.color()
}
if (mscolor.swatchID()) {
// it's a color variable
console.log("its a swatch")
}