Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

all open documents, add unnamed colors: swatch clean up

New Here ,
Oct 18, 2016 Oct 18, 2016

I am trying to cycle through all open documents and clean up the swatches pallet by:

  • showing unnamed colors
  • delete unused swatches

I got the unused swatches to clear, up, but I am having problems knowing how to get the unnamed colors to show up across all open documents. I can use the menu item name to get the page I am on to work, but I am having problems getting it to work across all open documents. I am sure it is a simple script to fix it all.

for(var i = 0; i < app.documents.length; i++){

    var myIndesignDoc = app.documents;

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

    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();

         } 

    } 

}

TOPICS
Scripting
659
Translate
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
Guide ,
Oct 18, 2016 Oct 18, 2016

Which version of Indesign are you using?

Translate
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
People's Champ ,
Oct 19, 2016 Oct 19, 2016

A color is unnamed as long as it hasn't been added to the swatch panel. So a possible approach would be to list swatches before and after you asked InDesign to ass the unnamed Colors. Then you can excerpt the colors that have been added.

Unless I am wrong.

Loic

Translate
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
New Here ,
Oct 19, 2016 Oct 19, 2016
LATEST

I am using CC 2014

Translate
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
Advisor ,
Oct 19, 2016 Oct 19, 2016

What about adding this to a function and creating an event listener for after open or beforeClose? something like this. The below will trash all unused swatches Before save.  you can use any event listener in place of "beforeSave" eventlisteners are Here >>>>>>> Need help with Multiple eventListeners <<<<<<<< This worked in my script.  This is as stated in an auto start script right now it will need modified if you do not need it to auto start.

    #targetengine "AutoStartScript"

  

   

app.addEventListener( "beforeSave", doTrashSwatch );

    function doTrashSwatch(){

     for(var i = 0; i < app.documents.length; i++){ 

    var myIndesignDoc = app.documents;  

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

    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();  

         }   

    }   

}

}

Translate
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
Advisor ,
Oct 19, 2016 Oct 19, 2016

Let me re phrase that.  I didnt have any unused colors in my test script.  This deletes all unused swatches (cmyk, Lab Pantone etc..) on any document that is saved.  But it does not show unnamed colors. 

Translate
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
Enthusiast ,
Oct 19, 2016 Oct 19, 2016

Hello fee1968

Give this code a try…

kind regards

Daniel (from Switzerland)

main();

exit();

function main() {

  var myDoc = app.activeDocument;

  if (myDoc != null) {

       $.writeln("Colors");

         // shows all colors also those whithout a name (then the name is empty)

       for (var i = 0; i < myDoc.colors.length; i++) {

            $.writeln(">" + myDoc.colors.name + "<");

       }

       $.writeln("Swatches");

       for (var i = 0; i < myDoc.swatches.length; i++) {

            $.writeln(myDoc.swatches.name);

       }

       var unusedSwatches = myDoc.unusedSwatches;

       $.writeln("\nunused Swatches: " + unusedSwatches.length);

       for (var i = unusedSwatches.length -1; i >= 0; i--) {

            $.write(unusedSwatches.name);

            unusedSwatches.remove();

            $.writeln(" deleted");

       }

   }

}

Translate
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