Change Text to Specific Colour Swatch Illustrator Javascript
Hi,
I have found a script online that takes all of the swatches that are used in an illustrator document and outputs each swatch name on its own line of text.

This works well, however I would like each line of text to also inherit the specific swatch colour.
So for example "1_Base_Hilite_70%" I would like this line of text to be coloured with the appropriate spot colour swatch with the same name and so on.
Can anyone please let me know what I need to add/amend to the below code to achieve this?
I am new to coding so please let me know if this is not the best place to post.
function swatchNamesToText() {
if (app.documents.length = 0) {
return;
} else {
var docRef = app.activeDocument;
var sel = docRef.selection;
if (sel.length == 1 && sel[0].typename == 'TextFrame') {
var nameList = Array();
var swatGrps = docRef.swatchGroups;
for (var i = 0; i < swatGrps.length; i++) {
var grpList = swatGrps[i].getAllSwatches();
for (var j = 0; j < grpList.length; j++) {
if (grpList[j].name != '[None]'
&&
grpList[j].name != '[Registration]'
&&
grpList[j].name != 'BRIGHT PINK - Poly 775' &&
grpList[j].name != 'White' &&
grpList[j].name != 'C=0 M=0 Y=0 K=100' &&
grpList[j].name != 'Black') {
nameList.push(grpList[j].name);
}
}
}
}
sel[0].contents = nameList.join('\n');
}
}
swatchNamesToText();
