Skip to main content
Known Participant
February 10, 2021
Answered

Indesign swatch name change

  • February 10, 2021
  • 3 replies
  • 803 views

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

 

This topic has been closed for replies.
Correct answer Charu Rajput

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.

 

3 replies

Community Expert
May 4, 2021

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:

 

 

Regards,
Uwe Laubender

( ACP )

BarlaeDC
Community Expert
Community Expert
February 10, 2021

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

Charu Rajput
Community Expert
Charu RajputCommunity ExpertCorrect answer
Community Expert
February 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 insensitive? If anyone knows please let me know.

 

Best regards
Davis_XIAuthor
Known Participant
February 10, 2021

THANK YOU!

Charu Rajput
Community Expert
Community Expert
February 10, 2021

You are welcome.

Best regards