Skip to main content
Aprking
Inspiring
December 7, 2024
Answered

How can I modify the color of existing Tags using a script in InDesign?

  • December 7, 2024
  • 1 reply
  • 428 views

Hello everyone! I have a question to ask.
I have added Tags ABCD in InDesign, and I want to use a script to change the color of these Tags during the operation, to distinguish between the state before and after the operation.
I have reviewed some related materials and found that the color of Tags can only be set when adding an XMLTag, but I can't find a way to modify the color of existing Tags using a script.
I hope someone can guide me.

Thank you all!

This topic has been closed for replies.
Correct answer m1b

Hi @Aprking, I don't understand what's going wrong. I just tried it here and it worked, for example:

app.activeDocument.xmlTags[1].tagColor = [200, 50, 255];

Does this work for you?

- Mark

1 reply

m1b
Community Expert
m1bCommunity ExpertCorrect answer
Community Expert
December 7, 2024

Hi @Aprking, I don't understand what's going wrong. I just tried it here and it worked, for example:

app.activeDocument.xmlTags[1].tagColor = [200, 50, 255];

Does this work for you?

- Mark

Aprking
AprkingAuthor
Inspiring
December 8, 2024

Thank you to @m1b  for your help. I have successfully completed the code to change the tagColor.

The previous failure was caused by other errors in the code. Thanks again!

 

 

var doc = app.activeDocument; 
var xmlTags = doc.xmlTags;

for (var i = 0; i < xmlTags.length; i++) {
    if (xmlTags[i].name == "A") {  
        xmlTags[i].tagColor = 1766025324;  
        break;  
    }
}

 

m1b
Community Expert
Community Expert
December 8, 2024

You're welcome. Hope your script goes great.