I'm work with CMYK colors - [C,M,Y,K] ~ [x,x,x,x]
Hi @eusoujp , Try this:
var groupName = "TEST"
var ds = app.activeDocument.swatches.everyItem().getElements();
var cg = makeColorGroup(app.activeDocument, groupName)
var gs = cg.colorGroupSwatches
for (var i = 0; i < ds.length; i++){
if (isColorValue(ds[i].name)) {
gs.add(ds[i])
}
};
/**
* Check if a CMYK color is named with its values
* @ param the swatch’s name
* @ return true if the swatch is named with its values
*
*/
function isColorValue(cn){
var ca = cn.split("=");
var n = []
for (var i = 0; i < ca.length-1; i++){
n.push(ca[i][ca[i].length-1])
};
if (n.toString() == "C,M,Y,K") {
return true
} else {
return false
}
}
/**
* Makes a new color group
* @ param the document to add the color group to
* @ param color group name
* @ return the new group
*/
function makeColorGroup(d, n){
if (d.colorGroups.itemByName(n).isValid) {
return d.colorGroups.itemByName(n);
} else {
return d.colorGroups.add({name:n});
}
}
Before run:

After:
