May 28 2008 • 4:28 PM

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
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
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.

14 Responses discussing this post. Add yours below.

  1. May 28th, 2008 • 10:00 pm • Link

    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. May 28th, 2008 • 10:05 pm • Link

    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. andrew
    May 28th, 2008 • 10:51 pm • Link

    …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. May 28th, 2008 • 11:38 pm • Link

    Thanks Russell, yes that’s way I would devised it.

  5. jerome
    May 29th, 2008 • 12:02 am • Link

    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.

  6. May 29th, 2008 • 12:33 am • Link

    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.

  7. jerome
    May 29th, 2008 • 3:17 am • Link

    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.

  8. May 29th, 2008 • 12:15 pm • Link

    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?)

  9. jerome
    May 29th, 2008 • 12:52 pm • Link

    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.

  10. Pat
    May 29th, 2008 • 1:50 pm • Link

    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.

  11. May 29th, 2008 • 1:55 pm • Link

    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.

  12. David Blatner
    May 30th, 2008 • 12:59 pm • Link

    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

  13. June 3rd, 2008 • 3:57 am • Link

    Or you can see what he looks like about 1:10 into the Transparencide video.

  14. July 9th, 2008 • 2:12 pm • Link

    [...] New design for InDesignSecrets.com blog * Free script extravaganza: Swatch Switcher, Label Graphics, Swap Object Positions, IndexMatic (beta) to index on character styles, Select [...]

Subscribe to the Discussion

Get the ongoing discussion surrounding "Swapping Color Swatches with Swatch Switcher" delivered to you. Click here to subscribe via RSS.

Leave a Reply

You can use limited HTML tags, such as <em></em> for emphasis/italics and <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> .

InDesignSecrets reserves the right to edit and/or remove posts and comments.