Indesign swatch name change

Explorer ,
Feb 10, 2021 Feb 10, 2021

Copy link to clipboard

Copied

We always use the same spot colour in all our documents but unfortunately its not always input the same way.

 

Is it possible to create a script to search for a name in the swatches panel and rename to keep it consistant.

 

Change 'Text Black' to 'Text black'.

 

I usually just change this manually but if i could add a script to my batch process scipts it would be great.

 

Thanks

 

Steph

 

TOPICS
Scripting

Views

170

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Adobe Community Professional , Feb 10, 2021 Feb 10, 2021
Hi, You can try following snippet to rename the swatch in single document, var doc = app.activeDocument; try { var blackSwatch = doc.swatches.itemByName('Text Black'); } catch (e) { } if (blackSwatch.isValid) { blackSwatch.name = 'Temp'; blackSwatch.name = 'Text black'; } NOTE: When I try to give name direct "Text black" before giving name as "Temp", it does not update. I am not sure about the reason, but I am also looking for a reason behind it. Is it because of case insensiti...

Likes

Translate

Translate
Adobe Community Professional ,
Feb 10, 2021 Feb 10, 2021

Copy link to clipboard

Copied

Hi,

You can try following snippet to rename the swatch in single document,

 

var doc = app.activeDocument;
try {
    var blackSwatch = doc.swatches.itemByName('Text Black');
} catch (e) {

}
if (blackSwatch.isValid) {
    blackSwatch.name = 'Temp';
    blackSwatch.name = 'Text black';
}

 

NOTE: When I try to give name direct "Text black" before giving name as "Temp", it does not update. I am not sure about the reason, but I am also looking for a reason behind it. Is it because of case insensitive? If anyone knows please let me know.

 

Best regards

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 10, 2021 Feb 10, 2021

Copy link to clipboard

Copied

THANK YOU!

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Feb 10, 2021 Feb 10, 2021

Copy link to clipboard

Copied

You are welcome.

Best regards

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Feb 10, 2021 Feb 10, 2021

Copy link to clipboard

Copied

Hi,

 

Just to add another solution in case someone is looking for something similar in the future.

 

var mySwatches = app.activeDocument.swatches;

// start at 4, because there are a number of swtches we cannot change.
for ( var  i = 4; i < mySwatches.length; i++){
    var mySwatch = mySwatches[i];
    mySwatch.name = standardisename ( mySwatch.name);
}


function standardisename (  name){
    // your code here to change the name as you want
    return name
}

 

This way you could apply style guides to the naming of swatches and have them enforced by a script.

 

Malcolm

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
May 04, 2021 May 04, 2021

Copy link to clipboard

Copied

LATEST

Hi Malcolm,

your script could fail because one can move around all swatches with names in brackets as well.

Obviously you assume that the swatches indexed 0,1,2,3 should never be touched.

 

Sample with my German InDesign where the swatches with index 0,1,2,3 are not the ones you'd expect:

 

SwatchesMovedAround-1.PNG

 

Regards,
Uwe Laubender

( ACP )

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines