Copy link to clipboard
Copied
need to change a bit on this script, specifically how it renames the color...
currently it is just adding the suffix "_CMYK" to the color swatch but because the name currently is "COLOR_SPOT" it ends up becoming "COLOR_SPOT_CMYK".
How can i change it to remove "_SPOT" and then append the suffix "_CMYK" so the new name will be "COLOR_CMYK"
the existing color will always have "_SPOT" at the end of the swatch name
//-------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------
//current script....
1 Correct answer
Change this line
sw.name = spotName + suffix;
to
// if spotName has the suffix _SPOT, remove it
if (spotName.slice(-5) == "_SPOT") sw.name = spotName.slice(0, -5) + suffix
else sw.name = spotName + suffix;
Explore related tutorials & articles
Copy link to clipboard
Copied
Change this line
sw.name = spotName + suffix;
to
// if spotName has the suffix _SPOT, remove it
if (spotName.slice(-5) == "_SPOT") sw.name = spotName.slice(0, -5) + suffix
else sw.name = spotName + suffix;
Copy link to clipboard
Copied
that worked perfect!!!!!
scott
Copy link to clipboard
Copied
Just for learning, here's a variation, that changes the suffix no matter which suffix is already applied, or adds it if none:
sw.name = spotName.replace(/(_SPOT|_CMYK)?$/, suffix);
In the regular expression, the | (bar) symbol means choose either _SPOT or _CMYK, and the ? means match the text in parentheses if it's there and the $ means match end of text—so if no suffix exists the $ replaces the end of text with the suffix.
- Mark

