2 Replies Latest reply on Jan 11, 2011 1:23 PM by [Jongware]-9BC6tI

    grep

    scriptworker

      I have this code in CS5:

       

      app.findGrepPreferences = NothingEnum.nothing;
      app.changeGrepPreferences = NothingEnum.nothing;
       
      app.findGrepPreferences.findWhat = '\(';
      app.changeGrepPreferences.changeTo = "?";
       
      app.activeDocument.changeGrep();

       

      app.findGrepPreferences = NothingEnum.nothing;
      app.changeGrepPreferences = NothingEnum.nothing;

       

      Just searching a ( and it does totally nothing!

       

      Can't figure out way. In the user interface it works correct :-(

       

      Can someone help?

       

      Michel

        • 1. Re: grep
          scriptworker Level 1

          Ah, it seems that the syntax is

           

          \\(

           

          2 slashes.

           

          Don't know why.

           

          Michel

          • 2. Re: grep
            [Jongware]-9BC6tI Level 4

            The reason is Javascript also uses the backspace character as "escape" for its special codes. If you search for something like

             

            \t

             

            using Javascript, you are not searching for "escape T" (as you would in the interface), but the Find field will actually contain a tab character -- something that's impossible to do in the interface. (Fortunately, InDesign doesn't mind this.)

             

            This example shows that the character string already gets translated once by Javascript, and inside Javascript the actual tab character is used. To "feed" InDesign a correct sequence of backslashes, you have to double them; the code "\(" gets translated to plain "(", and that is the code that appears in the Find What field.