6 Replies Latest reply on Apr 1, 2011 9:51 AM by Gary Niemeier

    How to use character styles in the Find/Change JavaScripts?

    Gary Niemeier Level 1

      First, good luck to Ole. He's been so helpful (and such a good writer, too). All the best!

       

      My Find/Change JavaScripts are running into trouble at line 159 of the ExtendScript Toolkit. The script is searching for a particular font, to which it should then apply a character style. I'm using the format I see in Adobe's "FindChangeList" sample text, but the script is still hitting a wall. What am I doing wrong? I'd like to have a working method for searching, not only for fonts, but also for finding a particular character or paragraph style and then applying a new style.

       

      Simple stuff, but I'm roadblocked.

       

      Here is the script so far:

       

       

      //This script applies the DFKai character style to the Arial Unicode font.


      text {findWhat:"", appliedFont:"Arial Unicode MS", fontStyle:"Regular"} {appliedCharacterStyle:"DFKai"} {include footnotes:true, include master pages:true, include hidden layers:true, whole word:false} Find Unicode font; change to DFKai character style.

       

       

      Thanks for your help!

       

      Gary Niemeier

        • 1. Re: How to use character styles in the Find/Change JavaScripts?
          Harbs. Level 6

          What version of InDesign is this with?

          • 2. Re: How to use character styles in the Find/Change JavaScripts?
            Gary Niemeier Level 1

            It's CS5. I noticed the example Find/Change text file (that came with CS5) actually referred to CS4. But it's clear that JavaScript changed with CS5. Thanks for your quick response. —Gary.

            • 3. Re: How to use character styles in the Find/Change JavaScripts?
              Mayhem SWE Level 2

              Gary Niemeier wrote:

               

              {include footnotes:true, include master pages:true, include hidden layers:true, whole word:false}

              This is not valid JavaScript, looks more like it was copied from an AppleScript but not modified properly. The property keys for the options should not contain any spaces, they must be written as:

               

              {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false}
              

              • 4. Re: How to use character styles in the Find/Change JavaScripts?
                Gary Niemeier Level 1

                You are absolutely correct. I don't know how those spaces got there! I copied the text from the "FindChangeList.txt" document, but somewhere along the way, a software program "helpfully" added the spaces. (Rest assured, it wasn't copied from AppleScript. I stick with JavaScript.) Anyway, the script now runs like a charm.

                 

                My thanks to you! Another "newbie" mistake easily spotted, eh?

                 

                One thing, though, if Adobe is reading this: please flesh out the "FindChangeList.txt" file for those who are not programmers/scripters. I'm just a normal InDesign user, and I really need examples of basic syntax in order to use the "Find/Change" script correctly. I'm referring to the syntax involved with finding or changing text with a certain character or paragraph style. I often search for styles, and those properties should be provided in the help file. A couple of samples are all that's needed. (I did read through the JavaScript reference guide provided by Adobe, and even in the "Find/Change" section, it did not provide this information!). Furthermore, I often search text for a specific font. Why isn't this syntax included as well? It would easy to do and would save users a lot of fumbling around.

                 

                Thanks again, all the best.

                • 5. Re: How to use character styles in the Find/Change JavaScripts?
                  Mayhem SWE Level 2

                  Gary Niemeier wrote:

                   

                  You are absolutely correct. I don't know how those spaces got there! I copied the text from the "FindChangeList.txt" document, but somewhere along the way, a software program "helpfully" added the spaces. (Rest assured, it wasn't copied from AppleScript. I stick with JavaScript.) Anyway, the script now runs like a charm.

                  If I were to guess, you copied the text from the comment part in the beginning of the example file and not from the part of the file which is actually executed. At least in the example scripts for CS3 this portion is wrong in this exact way and it seems they still haven't fixed it for the CS5 example scripts! Most likely the original author copied this part from the AppleScript version of the example scripts...

                  • 6. Re: How to use character styles in the Find/Change JavaScripts?
                    Gary Niemeier Level 1

                    Right again! I checked the file provided with InDesign CS5, and it does show the mistaken spacing in the comment section. That's where I copied it from. Not only is this sloppy scripting (some example, huh?) but the fact that the error has been squatting there since CS3... that shows a lack of attention to detail that is the opposite of the rigor needed for scripting success. Is there any way to bring this to Adobe's attention? Do they read the forum postings?

                     

                    I'm glad Adobe provides these forums. I appreciate the help from people like you. I hope Adobe will read this and decide to tighten up their scripting examples (and please provide more syntax examples for styles and fonts).

                     

                    All the best.