Skip to main content
Inspiring
December 30, 2011
Question

Delete unused swatches in InDesign CS5, js

  • December 30, 2011
  • 3 replies
  • 9624 views

Hi,

I need to select and delete unused swatches in InDesign CS5. I looked through OMV in "Swatches" and "Swatch", but I could not find any function to select unused swatch and delete it.

Am I looking for it in the wrong place?

And I also need to read color values for used swatches. I got this in OMV and was hoping it would give me an array of the color values for all existing swatches, but I am only getting "Object color":


mySwatches = myDoc.swatches[1].getElements();


alert (mySwatches)

Thank you for your help.

Yulia

This topic has been closed for replies.

3 replies

bagonterman
Inspiring
January 3, 2012

function trashUnusedSwatch(){

    while (myDocument.unusedSwatches[0].name != "") {

            id = myDocument.unusedSwatches[0].id;

            sw = myDocument.swatches.itemByID(id);

            sw.remove();

        }

    }

This should also work.

YuliaartAuthor
Inspiring
January 5, 2012

Love it!

Thank you.

PleaseWork1978
Inspiring
August 20, 2017

Do you realize you gave yourself, as the OP, the “correct answer” instead of the actual user who answered it.

Participating Frequently
January 2, 2012

Hi Yuliaart,

Try this script it will help ful.

# target "Deleting unused swatches change the gradient"
var myIndesignDoc = app.activeDocument;
var myUnusedSwatches = myIndesignDoc.unusedSwatches;
for (var s = myUnusedSwatches.length-1; s >= 0; s--) {
     var mySwatch = myIndesignDoc.unusedSwatches;
     var name = mySwatch.name;
// alert (name);
  if (name != ""){
mySwatch.remove();
}
}

Known Participant
October 12, 2012

Hi siva,

I am a beginner to Indesign scripting. I have a doubt in this script (Delete unused Swatches).

What is the correct meaning for the below command from your script? What this command actually did?

 

"if (name != "")"

 

I know, this command is used, not to affect the applied gradients, Can you please give some other similarity for this use of command?

I want to know the actual meaning and usage of this command

Can you please clear?

bagonterman
Inspiring
October 12, 2012

if the variable name does not equal nothing then remove the swatch.

Colin Flashman
Community Expert
Community Expert
December 30, 2011

check this thread, i think siva prasath has answered this (it is the last post in the thread)

http://forums.adobe.com/message/4059167

it deletes unused swatches and gradients without any ramifications.

to make it more useful, try adding this line to the start of the script:

app.menuActions.item("$ID/Add All Unnamed Colors").invoke();

as this will add any unnamed colours to the list of swatches, and then siva's script will remove all of the unused swatches/gradients.

If the answer wasn't in my post, perhaps it might be on my blog at colecandoo!