11 Replies Latest reply on Jun 6, 2010 8:23 AM by r.malekmohamadi

    set fill color of all words in list

    Timxhr877

      I want to change the fill color of all words in a document from a provided list of terms.

      For example, the following script works perfectly in Quark:

      set theIndexList to {"3rd Class", "4th class", "4th Class", "5th class", "5th Class", "7 lines of management/defense", "7 lines of management/defense", "7 Lines Of Management/Defense", "abalakov anchor", "Abalakov anchor", "Abalakov Anchor", "adze", "Adze", "Adze", "alpine rock", "Alpine rock", "Alpine Rock", "anchor", "Anchor", "Anchor"}

      tell application "QuarkXPress™ 4.11"
           tell document 1
               tell story 1
                   repeat with currentWord in theIndexList
                       try
                           set (the color of every text where it is currentWord) to "Green"
                       end try
                   end repeat
               end tell
           end tell
      end tell

      The purpose of this script is to highlight words for later indexing. I need to read through the document, see words someone else has chosen for indexing, then add them selectively to the index.

      InDesign CS, Mac OSX 10.3.9

        • 1. Re: set fill color of all words in list
          Steven.. Level 3

          you may want to try a grep style on Basic Paragraph style for these words, and that would allow you to turn on and off at will

          • 2. Re: set fill color of all words in list
            Timxhr877 Level 1

            I'm not clear on GREP style find/replace, because it doesn't appear to be a feature of InDesign CS(1), which my client specifically requested I use (don't ask why).

             

            I want a script to use in InDesign CS(1) that will do exactly what the sample Quark script does. I posted this question because I'm not clear why the same script -- modified for InDesign CS(1), of course -- doesn't work. I get this error, which I appologize for not posting earlier:

            InDesign CS got an error: Can't set fill color of every text of story 1 of document 1 whose it = item 1 of {"3rd Class", "4th class", "4th Class", "5th class", "5th Class", "7 lines of management/defense", "7 lines of management/defense", "7 Lines Of Management/Defense", "abalakov anchor", "Abalakov anchor", "Abalakov Anchor", "adze", "Adze", "Adze", "alpine rock", "Alpine rock", "Alpine Rock", "anchor", "Anchor", "Anchor"} to "Red".

            To clarify the issue: My client decided after the fact that they wanted an index in this hundred-page document. They supplied a list of terms for me to include in the index, so I needed a way to see each term in the document without having to read it line-by-line.

            Can anyone make the sample Quark script work in InDesignCS(1)?
            • 3. Re: set fill color of all words in list
              Shonkyin Level 3

              I have not idea about applescript but here is javascript code if you want use.

               

               

              var findForIndex = ["3rd Class", "4th class", "4th Class", "5th class", "5th Class", "7 lines of management/defense", "7 lines of management/defense", "7 Lines Of Management/Defense", "abalakov anchor", "Abalakov anchor", "Abalakov Anchor", "adze", "Adze", "Adze", "alpine rock", "Alpine rock", "Alpine Rock", "anchor", "Anchor", "Anchor"]
              for (a=0; a<findForIndex.length; a++)
              {
              app.changePreferences = NothingEnum.nothing;
              app.findPreferences = NothingEnum.nothing;
              app.changePreferences.fillColor = app.activeDocument.colors.item("Green");
              app.activeDocument.search(findForIndex[a], undefined, undefined,"");
              app.changePreferences = NothingEnum.nothing;
              app.findPreferences = NothingEnum.nothing;
              }
              

               

              Hope it will help you.

               

              Shonky

              • 4. Re: set fill color of all words in list
                sstanleyau Level 4

                I suspect you're going to have trouble finding someone still running CS to be able to answer your question without guessing. In recent versions you would use something like Shonkyin's code (although I'm not sure his color code is correct -- he's using a reference to a document color for change text preferences), but it was quite different in CS.

                • 5. Re: set fill color of all words in list
                  Shonkyin Level 3

                  I have tested my code before posting here in CS and its working.

                   

                  Shonky

                  • 6. Re: set fill color of all words in list
                    sstanleyau Level 4

                    My apologies, Shonkyin! I mis-remembered when the changes were made.

                    • 7. Re: set fill color of all words in list
                      Timxhr877 Level 1

                      Thank you, Shonky, for the JavaScript. It did exactly what I needed the

                      AppleScript to do.

                       

                      I remain curious as to why InDesign CS(1) can't use the AppleScript in

                      question. I have tried the AppleScript on InDesign CS3, and it does not

                      work there either.

                       

                      Thanks again,

                       

                      Tim

                      • 8. Re: set fill color of all words in list
                        sstanleyau Level 4

                        > I remain curious as to why InDesign CS(1) can't use the AppleScript in question.

                         

                        It was written for QuarkXPress; InDesign has a different (and more complex) object model.

                        • 9. Re: set fill color of all words in list
                          Timxhr877 Level 1

                          It's not a question of which program has more complex object model.

                          It's a matter of being able to solve a problem in the most

                          straightforward way possible with the tools available. It's certainly

                          not a Quark vs InDesign issue. They both have their merits and

                          drawbacks.

                           

                          In the case of this script, Quark allowed me to solve my problem more

                          quickly, but to InDesign's credit, JavaScript was available to solve

                          the problem.

                           

                          Because this is an AppleScript forum, I'll leave off with this request:

                          if anyone wants to write an AppleScript to solve this problem, I'd be

                          really interested to see it.

                           

                          --

                           

                          >> I remain curious as to why InDesign CS(1) can't use the AppleScript

                          >> in question.

                           

                          It was written for QuarkXPress; InDesign has a different (and more

                          complex) object model.

                          >

                          • 10. Re: set fill color of all words in list
                            sstanleyau Level 4

                            >It's not a question of which program has more complex object model

                             

                            Actually, it is largely. Search and replace in Quark relied on a combination of AppleScript whose clauses and a slightly odd definition of its text class. This made searches very simple, but it also meant they were restricted in what they could do. InDesign uses a more complex model, and exposes the full find/change engine; it's not as straight-forward, but it lets you do things that wouldn't be possible if they stuck to the whose clause approach.

                             

                            In fact you can use whose clauses similarly in InDesign, with one catch: InDesign has a different definition of what constitutes text (there is only 1 text per story), so it will only work if you're looking for one of the classes like words, lines, text style ranges, etc.

                             

                            I hesitate to rewrite the the js version in AS for CS because I don't have CS installed here. And there's an oddity involving color searches that makes it a bit more complicated than it should be. But it's very similar to the javascript.

                             

                            > Because this is an AppleScript forum

                             

                            I'm not sure what gave that impression, but it's far from so.

                            • 11. Re: set fill color of all words in list
                              r.malekmohamadi

                              lllllllllllllllllllllllllllllllllllllllllllllllhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh hhhhhhhhhhhh