3 Replies Latest reply on Sep 1, 2014 4:25 PM by theRightStoph

    Change character color according to a condition

    theRightStoph

      Hi there,

       

      I'm working on a list that contains color coded page numbers and letters (ie. A1...T17...Z8) and each of these need to be color coded according to the letter. The order is random so I want to be able to set either "Find/Change" or "Paragraph/Character Styles" to go through the list and apply a color. For instance, go through the list and all of the "z#" are red (z1, z2 ,z8 -->red, B1, B8, B5 -->Blue). Because they're not in order I would like to search the list, find the letter and change both the number and letter to a color I specify.  Is this possible? Would I have to create a GREP style or something?  Any help would be hugely appreciated, I'm not even sure where to begin. This seem like a macro that would be highly useful to people.  If I could think of an if statement it would be something like ...Search the list --> if "A(and any number)" are present --> Change the color to "Whatever I specify"

       

      Thank you so much in advance.

        • 1. Re: Change character color according to a condition
          Obi-wan Kenobi Adobe Community Professional

          Hi,

           

          26 lettres… 26 Grep styles as:

           

          A\d+

          Red

           

          B\d+

          Blue

           

          C\d+

          Green

           

          D\d+

          Orange

           

          • 2. Re: Change character color according to a condition
            rob day Adobe Community Professional & MVP

            If you want the list to be automatically updated as you edit, Obi-wan's 27 grep styles along with 27 swatches is the way to go.

             

            You could also do it with a script which would require less setup—the grep approach would need a paragraph style with 27 grep rules linked to 27 character styles using 27 swatches.

             

            This AppleScript (OSX only) picks up the first character of the paragraph and colors the paragraph text with a swatch named the same. So this short example uses uppercase A, B, C named swatches to color corresponding paragraphs starting with the same letter:

             

            Screen Shot 2014-09-01 at 4.40.54 PM.png

             

            tell application "Adobe InDesign CS6"

                --make sure there's a selection and get the text and its frame

                try

                    set c to {insertion point, character, word, line, paragraph}

                    if class of selection is in c then

                        set t to parent of selection

                    else if class of selection is text frame then

                        set t to parent story of selection

                    end if

                on error

                    display dialog "Please select some text"

                    return

                end try

               

                --get all of the story paragraphs

                set p to object reference of every paragraph of t

               

                --color each paragraph with the swatch that's named with the paragraph's first letter

                repeat with x in p

                    set c to character 1 of x as string

                    set s to (every swatch of active document whose name is c)

                    try

                        set fill color of every character of x to item 1 of s

                    end try

                end repeat

               

            end tell

            • 3. Re: Change character color according to a condition
              theRightStoph Level 1

              Thank you guys sooooo much, this is exactly what I was after! Perfect.