4 Replies Latest reply on Oct 6, 2009 3:02 AM by ramkumar.vp

    color removal

    Seth McGraw

      How can you (javascript) add unnamed colors and then subsequently select and delete unused colors in CS & CS2.


      In CS3 & 4 I can do it through menu actions (not supported in CS & CS2

        • 1. Re: color removal
          [Jongware] Most Valuable Participant

          You can't add unnamed colors in Javascript. Rather, that's what I learned, the hard way. But ...


          In CS3 & 4 I can do it through menu actions (not supported in CS & CS2



          Well ... as you said ... not in those older versions. Why not make up a name on the spot? It doesn't matter for its 'unused' status.


          The unused swatches can be found as a document property "unusedSwatches":


          Array of SwatchreadonlyThe swatches that are not being used.

          (you gotta love those helpful descriptions).

          Search the forum, I might of made someone else a working 'delete unused' script.


          [Edit] Got it; it's part of the script here: http://forums.adobe.com/thread/491014?tstart=1

          • 2. Re: color removal
            Seth McGraw Level 1

            Not sure what part to use...clarify?

            • 3. Re: color removal
              [Jongware] Most Valuable Participant

              Ah -- I see I used it the other way around (generating a list of used colors from the entire document swatch list -- and I was pretty content with this!).


              Off top of head, you might aim at sth like:


              while (app.activeDocument.unusedSwatches.length > 0)  app.activeDocument.unusedSwatches[0].remove();


              As you keep on removing item #0 (the first), the unusedSwatches array should decrease in length until it disappears into the tiny black hole inside your computer (leaving just its name and a zero length array as a lingering singularity).


              Untested, so it might object against stuff like mixed inks. Pretty sure it would work with fairly regular color swatches, tho'.

              • 4. Re: color removal
                ramkumar.vp Level 3

                Hi Seth / Jongware,

                I think this method will only work for normal swatches.

                In case of Gradiant swatches [manualy CMYK color applied] it wouldn't work, because of unnamed colors.

                So before deleting the swatch check its name not as empty.


                Sample Code:


                var myDocument = app.activeDocument;

                var found=0;
                var arrUnusedSwt=myDocument.unusedSwatches;
                for(var jj=arrUnusedSwt.length-1;jj>=0;jj--)