6 Replies Latest reply on Oct 19, 2016 6:51 AM by Fee1968

    all open documents, add unnamed colors: swatch clean up

    Fee1968

      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[i]; 
           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[s];  
              var name = mySwatch.name;  
          // alert (name);  
              if (name != ""){  
               mySwatch.remove(); 
               }  
          }  
      }
      
        • 1. Re: all open documents, add unnamed colors: swatch clean up
          tpk1982 Level 4

          Which version of Indesign are you using?

          • 2. Re: all open documents, add unnamed colors: swatch clean up
            Loic.Aigon Adobe Community Professional

            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 *** the unnamed Colors. Then you can excerpt the colors that have been added.

             

            Unless I am wrong.

             

            Loic

            • 3. Re: all open documents, add unnamed colors: swatch clean up
              cbishop01 Level 2

              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[i];   
               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[s];    
                      var name = mySwatch.name;    
                  // alert (name);    
                      if (name != ""){    
               mySwatch.remove();   
                       }    
                  }    
              } 
              }
              
              
              • 4. Re: all open documents, add unnamed colors: swatch clean up
                cbishop01 Level 2

                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. 

                • 5. Re: all open documents, add unnamed colors: swatch clean up
                  Daniel Sterchi Adobe Community Professional

                  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[i].name + "<");
                         }
                  
                         $.writeln("Swatches");
                         for (var i = 0; i < myDoc.swatches.length; i++) {
                              $.writeln(myDoc.swatches[i].name);
                         }
                  
                         var unusedSwatches = myDoc.unusedSwatches;
                         $.writeln("\nunused Swatches: " + unusedSwatches.length);
                         for (var i = unusedSwatches.length -1; i >= 0; i--) {
                              $.write(unusedSwatches[i].name);
                              unusedSwatches[i].remove();
                              $.writeln(" deleted");
                         }
                     }
                  }