Thanks for coming to InDesignSecrets.com, the world's #1 resource for all things InDesign!

Swapping Color Swatches with Swatch Switcher

Just when you get a comfort level with InDesign, because it works so well, something jumps out and surprises you. Case in point: Switching color swatches.

The project I was working on that brought this problem to light was a template that is built using a swatch palette of about 16 colors, all in the orange family. This template is going to be used over and over, but they may want the swatch palette to switch, at any point in production, from shades of orange to blue or green or maybe puce. (They won’t really use puce… Blatner bet me $5 I couldn’t work the word puce into this post.)

How do we achieve such a feat? Anyone who has swapped paragraph or character styles using the Load Styles feature would logically think that InDesign would handle swapping out colors the same way. With this train of thought, you would be able to name your color swatches as Color 1, Color 2, Color 3, etc. Then, when you want to change the orange swatches to the blue values (or puce… that’s $10, David!) you would just load a Blue.ase file (that’s an Adobe Swatch Exchange file, for the uninitiated) with the same swatch names (but blue color values). You’d think InDesign would then alert you that there are conflicts with same color names and ask you whether you want to keep existing, overwrite or rename.

It doesn’t.

Instead, it appends the new swatches, automatically renaming them by adding the word “copy” after the imported swatch name. Hmmm?

swatches1
Important Side Note: Swatch names are case-sensitive, so if you have an existing swatch named Color 1 and you import a swatch named color 1, it will not add the “copy” at the end… it just shows up as a different swatch.

Now you have imported your Blue.ase file and you have “Color 1” and “Color 1 copy” in the panel. If you delete “Color 1,” you may be asked which existing swatch you want to substitute it for, at which time you can select “Color 1 copy.”

Be aware that if the swatch hasn’t been used in the document yet (which could easily happen if you are changing the color on a template before production) the swatch will be deleted without InDesign first asking you.

Now, if you’re paid by the hour, this manual-deletion method is a valid solution to the problem — just make sure all color swatches are used (I put a bunch of frames filled with all swatches on the pasteboard of Master A) then manually delete and replace. But it’s a hassle if you need to be efficient.
So I asked my good buddy David Blatner, who now owes me $10, if he knew of a script that would do this automatically so it would be a cinch to change these colors from orange to blue or puce ($15). He said no, but…

With his vast network of friends and smart people (not to imply that his friends aren’t smart people) he had a script created, and it is here for you to test yourself. It was created by Steve Wareham, and you can download a zipped version here at this link (if you need unzipped, use this link). To learn more about Steve and his scripts, check out his Web site.
The script simply looks at your color panel and if it sees any with the name “copy” after it, replaces the original with the copy. That’s it, you’re done. So, in seconds, all of your Color 1, Color 2, etc. that are orange are replaced with the blues. You still need to manually load the .ase file with the colors of the same name, then run the script.

swatches2

The script also solves another flaw of InDesign: If you use gradients that are defined using swatches to assign color to the stops, and you use those gradients in the document, but you don’t use those swatches in the document also (as a solid, non-gradient stroke or fill), the swatch won’t be recognized when deleting it.

What does that mean? Say you have a gradient made of Color 1 and Color 9, and that gradient is the only use of those two swatches in the document, when you delete the swatches manually they just disappear–InDesign doesn’t offer you the option of swapping for Color 1 copy and Color 9 copy. This is another reason to have a swatch placed on the Master A, or wherever, so InDesign knows to swap the color for you.

But with Steve’s rockin’ script, you no longer need to have the swatches on the Master A because it switches the swatches in a way that recognizes unused colors and that, in turn, fixes the gradient problem.

Brilliant.

Thanks Steve for coming up with the beauty — and thanks, David, for the $15.

Russell Viers

Russell Viers

Russell Viers has taught many major publications and designers to work faster and improve quality. He has been actively involved with digital publishing since the early days, having started with CompuGraphic typesetting machines in the early ’80s, and PageMaker 1.0 in 1987. He has also authored several videos from lynda.com, Peachpit Press, and Total Training. Find more at russellviers.com.
Russell Viers

Latest posts by Russell Viers (see all)

  • - November 30, -0001
Related Articles
Comments

24 Comments on “Swapping Color Swatches with Swatch Switcher

  1. Reading it in a hurry, maybe if I could define the swatches using or building them up from a Mixed Ink Group, just changing (redefining) the base colors would do the task.
    Anyway I will give that script a run to enjoy its power. Thank you.

  2. The mixed ink group would be a good solution for spot colors, but not process, unless you wanted to create your entire document with spots then convert all spots to process in the Ink Manager.

  3. …in some ways, the way indesign handles same name colors is a safety feature rather than a flaw, in that, with quark (v6 and 7 too), for example, we’ve had situations whereby a source doc would have a different color but named the same as the target doc, the target doc changes the color throughout the file. This happened to us on a fairly large print run with a job with lots of listed colors, the pages color coding went off a bit, as the user in thumbnail mode, dragged pages over oblivious to what was really going on, nightmare. Sorry to mention quark…

  4. This is a good example of what scripting is good for. I had a similar type of project where we create a number of covers in various color pallets. When the job comes in there are a series of color options they want to see for the first pass so that they can decide which to use.

    I created a template with labeled text text boxes and rectangles that make up the base of the cover. Then a script is run, the user enters in the name of the book and the location of the templates and chooses some colors from a predetermined color pallet.

    The script creates a new document for each of the versions of the books (teachers and students as well as title pages for each) then, sets the new text in the appropriate text boxes (front cover, spine, and back cover) with the appropriate styles applied makes a series of pages with the various color options for each cover and saves the document.

    When it comes back from the client and they want to see another color option it swaps out the appropriate color in the open document all in a matter of seconds. When a final color is chosen then its just a matter of deleting the unwanted pages and its done.

    If you are not into scripting a manual way to do this would be to set up the template with a series of “Delete me” colors, then delete and replace with the desired colors, it takes a bit more time than a script and there is a bit more chance for error but it is a lot faster than doing it manually and takes just a bit more time upfront in building the template.

  5. This “copy” stuff in the color name reminds me of a great nuisance in Bookmarks: any copying of them — to a new document! — results in the names being either “XXX copy” or “XXX copy copy” or “XXX copy copy copy”! Quite infuriating. I’ve coped with this by exporting to INX and done search-replaces in a text editor, which sometimes has worked, other times has created a dysfunctional INX when I imported it. I have also had many bad crashes pertaining to Bookmarks in ID, so it seems the Bookmarks subsystem is — a substandard system. Do any of you folks here have any tips or tricks for Bookmark woes? I’d dearly like for David, Anne-Marie or the New Guys to dig into this, and spell it all out.

  6. I assume that you are talking about hyperlinks Klaus. If you are on a Mac you should be able to use an applescript like this:

    set OldDelim to AppleScript’s text item delimiters

    tell application “Adobe InDesign CS3″
    set theHyperlinks to every hyperlink of document 1
    repeat with aHyperlink in theHyperlinks
    set AppleScript’s text item delimiters to ” copy”
    set newName to name of aHyperlink
    try
    set name of aHyperlink to text item 1 of (newName)
    on error
    display dialog “Could not rename hyperlink ” & (name of aHyperlink)
    end try
    end repeat
    end tell

    This is pretty simple and takes the name of the hyperlink up to the first instance of ” copy” and uses that for the name and displays an alert to the user for duplicates.

  7. jerome, thanks. But I’m on Win, so Applescript isn on my menu. (I don’t really get why people bother with Applescript and the Win-only VB script, when JavaScript is dual platform?)

  8. I started with AppleScript before JavaScript was supported by Adobe. It is an easier language to program in because it is closer to the spoken language and allows for greater integration the computing environment that it is working on including other programs such as e-mail, word processors, spreadsheets, databases, etc. You can also run (Unix/OS X) shell scripts and in certain programs JavaScript. I can also build a full blown user interface with Apple’s free development environment.

    AppleScript’s can be attached to a folder so that they are triggered whenever a file is added, or stay open and watch a folder or series of folders for some event. You can set up rules in an e-mail program to run an AppleScript whenever you receive a message with the subject “ADD THIS.”

    JavaScript does have it’s place, it is great for dual platform scripts such as this which are just working inside of ID. It makes it a nice way for a developer to add functions to ID (or PS, ILL, etc) and deploy it to as many users as possible. However, if you want to build a robust work flow then that integrates well into your system then VB Script or AppleScript is probably a better choice.

  9. Just tried this script out and it works great! Thanks a lot guys. This site is great, it explains everything about InDesign and when InDesign can’t do something, you get that featured added. Awesome.

  10. Thanks for the kind words, Pat. What you don’t know is that the script also pings your PayPal account for $7.34 every time you use it…and sends it to me.
    Feel free to use the script regularly and tell your friends, as well.

  11. Regular readers of InDesign secrets who don’t know Russell will quickly become acquainted with his particularly sharp sense of humor (thus his comments about paypal and so on… just a joke! Really!).

    For more on Russell’s humor, you (and everyone you know) should visit yabb-adobe-doo.com

  12. Pingback: InDesignSecrets » Blog Archive » InDesignSecrets Podcast 081

  13. Thanks for the helpful tip. Have an unusual situation that maybe someone can help me with.
    I inherited a template for a client that uses only spot colors and will stay that way. This template will be repurposed for a number of projects that will have various color schemes, also only using spot colors (btw, all will be Pantone Standard).
    All the Paragraph, Character, and Object Styles use these colors, as well as Master Pages.
    Question, Can I use this to swap out one swatch (using a Pantone Spot color) for another (also using a Panton Spot)?
    thanks
    Sam

  14. Thank you Steve for contributing that script. However, if you are not working with an english version of InDesign the script will fail detecting the “copy” status of the swatch you want to apply.
    Still I have not found an universal method for all localized version of InDesign, but I came to a solution for my german version:
    1. step:
    instead of “copy” just write “Kopie” in the following line of code. For the german version from:
    if (myTempStringSlice == ‘copy’)
    to:
    if (myTempStringSlice == ‘Kopie’)
    2. step:
    because the new word “Kopie” has a character count of 5 instead of 4 you have to change the following line of code accordingly from:
    myTempStringSlice = myTempString.slice((myTempString.length-4), myTempString.length);
    to:
    myTempStringSlice = myTempString.slice((myTempString.length-5), myTempString.length);
    3. step:
    The same is true for the next line of code.
    From:
    myTempStringSlice = myTempString.slice((myTempString.length-5), myTempString.length);
    to:
    myTempStringSlice = myTempString.slice((myTempString.length-6), myTempString.length);
    Just save the script under a new name like “swatch_switch_DE.jsx”.

  15. Thanks so much for this script. I have to make docs with a variety of colors and this makes it so easy to change. A nice enhancement would be a command in it to load a specific .ase file. Then one could have variations of the script named red, yellow, blue, green, purple etc…

  16. Pingback: InDesignSecrets » Blog Archive » Grouping Color Swatches

  17. What if I want to keep the extra swatches in my template so my designers use the same bank of colors over time?

    • I am also in need of this option of automating a swop out of coated to uncoated swatches in InDesign. did you ever find a solution?
      We are also testing the accuracy of our RIP converting spot Lab pantone to cmyk.

  18. Do you think it’s possible to add more functions to this script? We’re using it in our multi-brand workflow and it seems like the next logical step is to add more scripting to automate more tasks. For example swapping out logos, linked graphics and paragraph styles. I’ve done a screencast to show the workflow. Can’t believe how powerful inDesign is now.

    https://www.youtube.com/watch?v=kK-fIHMdSUY

Leave a Reply

Your email address will not be published. Required fields are marked *