15 Replies Latest reply on Jan 12, 2012 11:32 PM by Colin Flashman

    GREP question: Changing all caps to proper name punctuation

    Rand0mUser Level 1

      Hello,

       

      I'm working on my subscription renewal letter.

       

      In our mailing database, all names of people and business are in capitals. I need to change them to regular capitlization for the letter.

      Example: "JOHN SMITH" should be "John Smith"

       

      I know how to find the text, but I don't know exactly how to repace it. Help would be much appreciated.

       

      Screen shot 2012-01-12 at 3.54.53 PM.png

       

      Regards,

      Eric

        • 1. Re: GREP question: Changing all caps to proper name punctuation
          Peter Spier Most Valuable Participant (Moderator)

          This has to be done either manually or by script -- no way to change to Title Case in the Find/Change dialog. If you search areound here a bit, thoogh, I think you'll find some scripts already written to do it. Seems like sombody else asked last week...

          1 person found this helpful
          • 2. Re: GREP question: Changing all caps to proper name punctuation
            Rand0mUser Level 1

            I found a script (coding below) by Dave Saunders: http://jsid.blogspot.com/2005/08/script-of-day-smart-title-case.html

             

            I need it to be slightly modified so that instead of applying to the selected text, it finds (?<=Dear\s|Cher\s).+

             

             

             

            ------------------------------------------------------------------------------------------ ----------------------------------

            //DESCRIPTION: Converts selected text to title case smartly

             

            // Customize this script by either editing these arrays:

            var ignoreWords = ["a","an","and","the","to","with","in","on",

            "as","of","or","at","is","into","by","from","for"];

            var intCaps = ["PineRidge","InDesign","NJ","UMC"];

             

            // or by creating text files named ignoreWords.txt

            // and intCaps.txt in the script's folder

             

            ignoreWords = getIgnoreFile(ignoreWords);

            intCaps = getIntCaps(intCaps);

             

            try {

            myText = app.selection[0].texts[0].contents;

            } catch(e) {

            exit();

            }

             

            theWords = myText.toLowerCase().split(" ");

             

            //First word must have a cap, but might have an internal cap

             

            myNewText = "";

            for (var j = 0; theWords.length > j; j++) {

            k = isIn(intCaps,theWords[j])

            if (k > -1) {

              myNewText = myNewText + intCaps[k] + " ";

              continue;

            } else {

              if ((isIn(ignoreWords,theWords[j]) > -1) && (j != 0)) {

               myNewText = myNewText + theWords[j] + " ";

              } else {

               myNewText = myNewText + InitCap(theWords[j]) + " ";

              }

            }

            }

             

            app.selection[0].texts[0].contents = myNewText.substring(0,myNewText.length - 1);

             

            // +++++++ Functions Start Here +++++++++++++++++++++++

             

            function getIgnoreFile(theWords) {

            var myFile = File(File(getScriptPath()).parent.fsName + "/ignoreWords.txt");

            if (!myFile.exists) { return theWords }

            // File exists, so use it instead

            myFile.open("r");

            var importedWords = myFile.read();

            myFile.close();

            return importedWords.split("\n"); // Could filter these, but what's the point?

            }

             

            function getIntCaps(theWords) {

            var myFile = File(File(getScriptPath()).parent.fsName + "/intCaps.txt");

            if (!myFile.exists) { return theWords }

            // File exists, so use it instead

            myFile.open("r");

            var importedWords = myFile.read();

            myFile.close();

            return importedWords.split("\n"); // Could filter these, but what's the point?

            }

             

            function getScriptPath() {

            // This function returns the path to the active script, even when running ESTK

            try {

              return app.activeScript;

            } catch(e) {

              return e.fileName;

            }

            }

             

            function isIn(aList,aWord) {

            for (var i = 0; aList.length > i; i++) {

              if (aList[i].toLowerCase() == aWord) {

               return i;

              }

            }

            return -1;

            }

             

            function InitCap(aWord) {

            if (aWord.length == 1) {

              return (aWord.toUpperCase());

            }

            return (aWord.substr(0,1).toUpperCase() + aWord.substring(1,aWord.length))

            }

            • 3. Re: GREP question: Changing all caps to proper name punctuation
              Jeffrey_Smith Most Valuable Participant

              You could select the name column and change to Proper Case in Excel before you create your merge data source...

              • 4. Re: GREP question: Changing all caps to proper name punctuation
                Hutch75

                Try Multi-Find-Change from www.automatication.com. It is a nice little plug in that gives a lot more functionality to Find/Change.Screen Shot 2012-01-13 at 10.34.17 AM.png

                • 5. Re: GREP question: Changing all caps to proper name punctuation
                  Peter Spier Most Valuable Participant (Moderator)

                  I'm not a scripter, so I can't help with altering Dave's script, but I can tell you that it is meant to work on a selection. If you want to do an entire document you'll probabley want to do something clever like assign a script label to the field containing the text you need to change and add a loop to the scrip that will traverse the document looking for the label.

                  • 6. Re: GREP question: Changing all caps to proper name punctuation
                    Rand0mUser Level 1

                    I purchased Multi-Find-Change.

                     

                    What do I put in the 'Change to:' field? I want the same text to remain.

                    • 7. Re: GREP question: Changing all caps to proper name punctuation
                      Hutch75 Level 2

                      Hi, I would use /w+ in the find field and $0 in the change to field (there is bound to be better ways I'm sure, but this works for me). Save this query and in MFC make a new set and select your query from the GREP list. Click on your query in the set and click the 'Pin' icon and select Title Case then change all from MFC.

                      • 8. Re: GREP question: Changing all caps to proper name punctuation
                        [Jongware] Most Valuable Participant

                        Nope. GREP cannot change case (it can, but only in the very limited sense that you can search for 'A' and replace with 'a'). It cannot for 'any' string -- and Title Case is not an option in the Replace With formatting field.

                        • 9. Re: GREP question: Changing all caps to proper name punctuation
                          Hutch75 Level 2

                          Hi Jongware, not sure if you have followed the thread but my last reply was referring to using Multi-Find-Change and my method does work with this.

                          • 10. Re: GREP question: Changing all caps to proper name punctuation
                            [Jongware] Most Valuable Participant

                            Here is a Javascript that changes the case of everything following "Dear" or "Cher" to Title Case:

                             

                            app.findGrepPreferences = null;
                            app.findGrepPreferences.findWhat = "(?<=Dear|Cher).+";
                            foundList = app.activeDocument.findGrep(true);
                            for (i=0; i<foundList.length; i++)
                              foundList[i].changecase (ChangecaseMode.TITLECASE);
                            

                             

                            Be aware that not all names should be in Full Title Case: Fatima Moreira de Melo, for example (hah -- no comments from aroused Dutchmen please ). There is no way to handle names like these automatically, as there are national preferences -- prefix in "de Jong" is lowercase in Holland, "De Jong" in Belgium -- as well as personal ones. And then there are Irish and Scottish names such as "O'Connor" and "MacMillan"!

                            • 11. Re: GREP question: Changing all caps to proper name punctuation
                              [Jongware] Most Valuable Participant

                              Ah, so it's more than just a repeatable version of ID's native Find/Change capabilities. Didn't know that, thanks for pointing it out.

                              • 12. Re: GREP question: Changing all caps to proper name punctuation
                                Peter Spier Most Valuable Participant (Moderator)

                                Jongware, I have no idea how the OP has got styles set up, but maybe you should add some sort of additional formatting restriction, like set a find option for a paragraph style, or position at start of paragraph or something so you don't wind up title casing the ends of the odd paragraph here or there that happen to mention that singer who used to hang out with a guy named Sonny.

                                • 13. Re: GREP question: Changing all caps to proper name punctuation
                                  [Jongware] Most Valuable Participant

                                  Sure. If this line always has the same style (and this is another style than the ones mentioning mid-70s singers), add this line below the first:

                                   

                                  app.findGrepPreferences.appliedParagraphStyle =
                                    app.activeDocument.paragraphStyles.item("Insert Style Name Here");
                                  
                                  • 15. Re: GREP question: Changing all caps to proper name punctuation
                                    Colin Flashman Adobe Community Professional

                                    the OP says "mailing database" so unless the OP wants to merge to a new indesign file and then double-handle the artwork by fixing the artwork AFTER it is merged, i'd be tempted to fix the database in something like excel, changing all cases to "Proper" and then use a GREP style solution below. This way the file can be output directly to the printer or PDF without having to double handle the file.

                                     

                                    as for the names such as "van Gastel", "McMurray", "O'Connor", then GREP styles MIGHT be able to help you. i wrote a blog about it at: http://wp.me/p1x3Yg-3y - go to the part of the story headed "Changing Surnames". Ironically, Jongware helped me out with this solution - it certainly fixes "Mc" names, "O'..." names, and perhaps hyphenated names, but as for middle names which are all lowercase, not so sure.

                                     

                                    The key to the above solution though DOES INVOLVE fixing the excel file first to be proper case.