12 Replies Latest reply on Dec 4, 2010 8:19 AM by tpk1982


    tpk1982 Level 4

      Why the javscript omits slashes, when i wrote something in GREP. Is it possible to include slashes using JS?

        • 1. Re: GREP/JS
          Harbs. Level 6

          You need to escape your slashes in scripts.


          "\" becomes "\\" and "\\" becomes "\\\\"...



          • 2. Re: GREP/JS
            tpk1982 Level 4



            Thanks for yur quick reply. Thats working perfectly. I want to apply a character style. I got a script from another person.


            var myParaStyles = app.activeDocument.allParagraphStyles;
            for (var i = 0; i < myParaStyles.length; i++){
                    var myParaGrep = myParaStyles[i].nestedGrepStyles.add();
                    myParaGrep.grepExpression = "{put GREP expression}";
                    myParaGrep.appliedCharacterStyle = "{put Character Style Name}";

            But it does not take the character style. Whats wrong?

            • 3. Re: GREP/JS
              [Jongware] Most Valuable Participant

              Just to make sure -- Are you replacing this correctly with the character style name? Does that style name exist? Is it in a group?


              {put Character Style Name}

              • 4. Re: GREP/JS
                tpk1982 Level 4

                Yes, am copy and paste the character style name. But it does not apply.

                • 5. Re: GREP/JS
                  grefel Level 2

                  you cannot submit a string into a nested grepStyle.

                  a quick fix would be:



                          myParaGrep.appliedCharacterStyle = "{put Character Style Name}";



                          myParaGrep.appliedCharacterStyle = app.activeDocument.characterStyles.itemByName("{put Character Style Name}");


                  this won't work with characterStyleGroups



                  • 6. Re: GREP/JS
                    tpk1982 Level 4

                    Excellent, it's working. Another one, my GREP code is,



                    How can i give that closing quotes?

                    • 7. Re: GREP/JS
                      [Jongware] Most Valuable Participant

                      Use the regular code ~} for curly double closing quotes.




                      r/wThe character style applied to the text. Can also accept: String.



                      • 8. Re: GREP/JS
                        Marijan Tompa [tomaxxi] Level 4

                        Yes, that's my snippet.

                        Thanks Jongware for pointing out that appliedCharacterStyle can accept String also.

                        I tested snippet and it worked just fine for me.

                        Also I put those commenting strings just like placeholders.





                        • 9. Re: GREP/JS
                          grefel Level 2

                          hey tomaxxi + jongware,


                          string is not working here. with a german indesign cs5 + cs4 and windows 64 bit i get an:


                          Error: Invalid value for set property 'appliedCharacterStyle'. Expected CharacterStyle or String, but received "ziffer".


                          character style 'ziffer' is in place!


                          by the way: i think you don't really need a try/catch just start the for-loop at 1 omitting the [No Paragraph Style] style.



                          var _dok = app.activeDocument;
                          var _absFormate = _dok.allParagraphStyles;
                          for (var i = 1; i < _absFormate.length; i++) {
                              var _format = _absFormate[i].nestedGrepStyles.add();
                              _format.grepExpression = "//d";
                              _format.appliedCharacterStyle = getCharacterStyle("ziffer");
                          function getCharacterStyle (_name) {
                              for (var i = 0; i < _dok.allCharacterStyles.length; i++) {
                                  if (_dok.allCharacterStyles[i].name == _name ) return _dok.allCharacterStyles[i];
                              return null;



                          • 10. Re: GREP/JS
                            Peter Kahrel Adobe Community Professional & MVP



                            This error message:


                            > Error: Invalid value for set property 'appliedCharacterStyle'. Expected CharacterStyle or String, but received "ziffer".


                            is misleading as it suggests that you can set the style with a string. But you can't: you have to use an object, as in


                            . . . = myDoc.characterStyles.item ("ziffer");



                            • 11. Re: GREP/JS
                              grefel Level 2

                              hey peter,


                              we have been talking about this issue - the documentation seems to be wrong. BUT tomaxxi's and jongware's indesign instances are happy with a string... anyway we can close this topic ... a nested GREP style is a minor issue.





                              • 12. Re: GREP/JS
                                tpk1982 Level 4

                                Hi everybody,


                                Thanks for your valuable anwers.