4 Replies Latest reply on Jun 25, 2008 11:03 AM by (Gary_Niemeier)

    "TextCleanup" JavaScript Trips Up on Character Style

      Hi, I'm making use of Adobe's supplied JavaScripts for Indesign. I'm using IndyCS2 ver. 4.0.5 on MacOSX 10.4.10. On Ole's advice, I've been running the "TextCleanup" JavaScript. It works great using simple text strings with no formatting. However, when I plug in the formatting examples provided in the companion text file (ASFindChangeList.txt), it trips up, (even on the simple supplied examples, like applying the character style "price" to $10.00.)

      In this instance, I'm searching for Chinese text, and will replace it with a character style. The "find" is:

      {findText:"", appliedFont:"MS Mincho", fontStyle:"Regular"}

      The "change" is:

      {applied character style:"Kai"}

      An error is generated:

      Source: app.changePreferences.properties = {applied character style:"Kai"}
      Offending Text: character

      I've used the ExtendScript Toolkit to peek into other supplied scripts, but haven't been able to figure out where I'm going wrong. Question 1: what should be the "change" wording that will run the script properly?

      Finally, a bigger question: where can I go to find the correct terms to use when describing formatting in the "ASFindChangeList.txt" document? I've looked at Adobe's Scripting Reference, but it's totally over my head. I'm not an experienced scripter, but am willing to learn.

      Thanks kindly for your help.

      Gary
        • 1. Re: "TextCleanup" JavaScript Trips Up on Character Style
          Level 1
          Hi Gary,

          Try:

          {appliedCharacterStyle:app.documents.item(0).characterStyles.item("Kai")}

          The text file stores the terms *in the relevant scripting language*. ASFindChangeList.txt uses AppleScript terminology. If you're using the JavaScript version of the script, you need to use the JavaScript terms.

          In general, the JavaScript versions are the same as the AppleScript versions with the spaces removed and internal caps inserted after each (former) space. So "applied character style" becomes "appliedCharacterStyle".

          You can find these by looking at the properties of the FindPreferences object in the JS reference.

          Thanks,

          Ole
          • 2. Re: "TextCleanup" JavaScript Trips Up on Character Style
            Level 1
            Ole,

            Thanks again for the fast response. I misspoke in my question: I was using "JSFindChangeList", not the AppleScript version. The JS version does actually use the "applied character style" term, with lowercase and spaces. Just a heads-up.

            At any rate, the string you supplied works like a charm, thank you. I printed out the properties you pointed out in the JS reference and will refer to those in the future.

            I noticed that a different post in this forum recommended the book "Scripting InDesign with JavaScript" by Peter Kahrel. (It's a 50-page "ShortCut" PDF book by O'Reilly.) Do you also recommend it? What's the best book to take an InDesign expert from zero to 65 mph using JavaScript?

            Thanks again,

            Gary
            • 3. Re: "TextCleanup" JavaScript Trips Up on Character Style
              Level 1
              Hi Gary,

              Peter's book really is quite good, and, in my opinion, well worth the cover price.

              In addition, for CS3, I was able to significantly expand the tutorial matter in the Scripting Tutorial and Scripting Guide (which is now all example scripts, rather than being a monumental reference PDF)--you should also take a look at those, as almost all of the scripts will work with CS2. All of the scripts referred to in the Scripting Guide can be downloaded (as a single archive) on the InDesign scripting home page referred to at the top of this forum. (Don't try to copy/paste the scripts out of the PDF--most of them are only fragments of complete scripts stored in the archive.)

              You might want to start with the "Working with Text" chapter in the Scripting Guide--I tried to cover the most common things people might want to do with text.

              If you wanted to try working with AppleScript, Shirley Hopkins has a book available (try Amazon) that's also good. And the AppleScript Pro seminars presented by Scripting Matters (that's Shane Stanley and Ray Robertson) are great once you've gone beyond the "raw beginner" stage (http://www.scriptingmatters.com).

              This forum is also a great resource! Don't hesitate to ask questions.

              Thanks,

              Ole
              • 4. Re: "TextCleanup" JavaScript Trips Up on Character Style
                Level 1
                Ole,

                Thanks for the wealth of info. I bought Peter's book; it looks very good. I pulled the tutorials and guides you mentioned above from my CS3 disc and will be using those going forward. Interesting you mention Shirley; I met her at Shane & Ray's Monterey Applescript sessions in 2002 (unfortunately, I was in the "raw beginner" stage you mentioned, and most of the session went over my head).

                If someone is starting with Mac-based scripting on the ground floor, should the newbie focus on Applescript or JavaScript? My initial efforts would be focused on InDesign. Does one language "inform" the other? I'm guessing the programming concepts are largely identical.

                Thanks again,

                Gary