Back

If your email is not recognized and you believe it should be, please contact us.

  • You must be logged in to reply to this topic.Login

Need advice re: scripting and GREP

Return to Member Forum

  • Author
    Posts
    • #80761
      cknighton
      Participant

      Greetings all, I’m new to scripting and GREP and need a little guidance.

      I have a batch of old documents with copy typed (sloppily) in Title Case. (Note that this isn’t the format setting accessible through the Type menu, it’s actual caps typed throughout the text.) We’d like this copy in normal sentence case. I found a script that handled that task nicely (via https://forums.adobe.com/thread/899486?start=0&tstart=0 ). It gave me a new problem though: All the things that are supposed to be capped, like names, now aren’t. I expected this, but need some advice on the best way to handle it.

      We deal with retail real estate and I have a custom dictionary that includes both industry terms and lots of retailers with their caps properly set (PetSmart, for example.) There’s also acronyms and such that need proper caps.

      Running a case-sensitive spell check has proven far too time consuming. I found that GREP styles work well, but there’s starting to be an awful lot of them. FindChangeByList.jsx looked promising, but I now see that every instance needs to be set up individually. This is working well for things like {findWhat:”(NYSE|nyse)\: [\u]+”} {appliedCharacterStyle:”all_caps”} but FindChangeByList looks like I’ll need to set up every retail name individually. There’s so many of them!

      So, first question, when is it better to use GREP styles vs a script for jobs like this? Second, I’d like to tell indesign: “Scan all text against this list, and if you find any caps that don’t match, fix it.” Is that possible, and if so, can someone point me to a resource?

      I’m already learning scripting and GREP both, but it’s a little harder to know what to do next, when I’m not sure which hammer to swing. All help appreciated, thanks in advance!

    • #80779
      David Blatner
      Keymaster

      I don’t have an answer to this immediately, but I wanted to just let you know that your forum post was held for moderation for some reason (unclear why) and I just posted it. Sorry for the trouble.

    • #80793
      cknighton
      Participant

      Thank you! I wondered why it didn’t appear. Hope you didn’t find six of them waiting for attention.

    • #80796
      Peter Kahrel
      Participant

      GREP styles can change form, not substance: they can apply formatting, but can’t change the text itself. You suggested what would seem the most appropriate approach: use a word list to fix case after the change to sentence case. The very rudimentary script below does just that.

      To use the script, open the word list that has all words in their correct case (PetSmart, InDesign, NATO, RSPB), each word on a new line. Then open the document that needs to be treated and change its content’s case to sentence case. Make sure that the text and the list are the only two open documents and that the text is the active document. Then run the script.

      The script reads the list, then looks in the text for the lower-case instance of each list item, case-insensitive (?i) and whole word only (). Case-insensitive searches are needed because sentence case may have rendered unfindable words at the beginning of sentences, such as Nato and Indesign.

      As I said, it’s rudimentary but the basics are there and it can be refined in all kinds of ways.

      (function(){
        app.findGrepPreferences = app.changeGrepPreferences = null;
        var list = app.documents[1].pages[0].textFrames[0].parentStory.contents.split('\r');
        for (var i = 0; i < list.length; i++) {
          app.findGrepPreferences.findWhat = '(?i)b' + list[i].toLowerCase() + 'b';
          app.changeGrepPreferences.changeTo = list[i];
          app.documents[0].changeGrep();
        }
      }());

      Peter

      • #80983
        cknighton
        Participant

        Hi Peter, I apologize for the delay in responding, it took a few days before I was able to try the script. It’s perfect! Does exactly what I need. I appreciate the simplicity, looks like it could be a good starting point to adapt as I learn more about scripting.

        I have been giving FindChangeByList a workout on other tasks, like cleaning up every conceivable acronym for “per square foot” to PSF. Between your script, FindChangeByList, and the Saunders script, in a few minutes we’re correcting abominable copy to about 90% accuracy. This will save me hours of work updating legacy docs.

        A thousand thanks for your time and assistance. Very much appreciated!

Viewing 3 reply threads
  • You must be logged in to reply to this topic.
Forum Ads