14 Replies Latest reply on Mar 13, 2017 3:48 PM by thaero17058

    InDesign Script

    thaero17058 Level 1

      Hello

      I want to know : can we using InDesign Script to select any text between 2 specific glyph + if the selected text at the beginning of line ( beginning of line . not the beginning of paragraph ) ... then change it to specific word + create a new character style for the selected text .

      .

      .

      .

      Thanks

        • 1. Re: InDesign Script
          Obi-wan Kenobi Adobe Community Professional

          "Yes we can!"

          (Scripting motto)

           

          (^/) 

          1 person found this helpful
          • 2. Re: InDesign Script
            thaero17058 Level 1

            Thanks obi-wan Kenobi

            can you tell me how can i do this ?

            • 3. Re: InDesign Script
              Obi-wan Kenobi Adobe Community Professional

              Aha! Next time, I shall say nothing! 

              Well, can you show a screenshot? Thanks!

               

              (^/)

              • 4. Re: InDesign Script
                thaero17058 Level 1

                Thanks

                this is an example of my work in Arabic : if we want InDesign to select any text between these 2 glyphs ... then if the selected text located at the beginning of any line in paragraph ( not at beginning of paragraph ) replace the selected text to another text like  " بسم الله "

                then create a new character style for the converted text (  بسم الله ) :

                Untitlefhdhd.png

                and this is another example with English , but the same idea :

                uiyguigouh.png

                • 5. Re: InDesign Script
                  uniqued_tol Level 1

                  Hi thaero;

                  Try this:

                  exam.jpg

                   

                  find Grep: (?<=\x{F08C}).+?(?=\x{F08D})

                  • 6. Re: InDesign Script
                    Obi-wan Kenobi Adobe Community Professional

                    Do you keep the 2 glyphes, before and after?

                     

                    (^/)

                    • 7. Re: InDesign Script
                      thaero17058 Level 1

                      yes

                      • 8. Re: InDesign Script
                        Obi-wan Kenobi Adobe Community Professional

                        Not clear!

                         

                        1/ Could you have such a similar text several times in a same paragraph?

                        2/ … and not necessarily with the first glyph at the end of a line?

                         

                        2 questions, so 2 answers! 

                         

                        (^/)

                        • 9. Re: InDesign Script
                          thaero17058 Level 1

                          1/ yes , but i want to convert only the text between glyph .

                          2/ No , it is necessary ... so the selected text located at the beginning of the next line .

                           

                           

                          2 question ... 2 answers

                          • 10. Re: InDesign Script
                            thaero17058 Level 1

                            Thanks uniqued_tol

                            the problem not with GREP but with scripting >>> if the selected text ( by GREP ) located at the beginning of line ... replace the selected text to another text >>> then create a new character style for the new text .

                             

                            • 11. Re: InDesign Script
                              Obi-wan Kenobi Adobe Community Professional

                              … Humm!

                               

                              Well, look at this:

                               

                              Capture d’écran 2017-03-13 à 20.22.44.png

                               

                              We search all text between 2 glyphes: "@" and "#"!

                              … and shall replace by "Yes we can!" (+ "Red" char style) as:

                              Capture d’écran 2017-03-13 à 20.26.00.png

                               

                              The difficulty (if right!) is that the following occurrences of the same para are going to "move" after the first replacing!

                              For this reason, only the script can evaluate the occurrence to be treated, only at each step after trying to treat each of them!!!!

                              The op can't!

                              E.g, in the first screenshot, you could try to say: "Only the first occurrence of the second para will be treated! …" but you would be wrong: The two occurrences will be done! 

                              As:

                               

                              Capture d’écran 2017-03-13 à 20.24.11.png

                               

                              (^/)

                              1 person found this helpful
                              • 12. Re: InDesign Script
                                thaero17058 Level 1

                                This is exactly what i need

                                Thanks a lot

                                 

                                Can you send this script to me ... please .

                                • 13. Re: InDesign Script
                                  Obi-wan Kenobi Adobe Community Professional

                                  … That seems to work!! 

                                   

                                  [ … To be validated! ]

                                   

                                   

                                  /*
                                      0122_FindReplace_MichelAllio.jsx
                                      Script written by Michel Allio [2017/03/13]
                                      See: https://forums.adobe.com/thread/2289146
                                      Object:
                                      • Research text between 2 glyphes
                                      • Replace by other text + apply a char style ONLY IF at the the two first char found aren't on the same line!!
                                  */
                                  
                                  
                                  redraw = app.scriptPreferences.enableRedraw;  
                                  app.scriptPreferences.enableRedraw = 0;
                                  
                                  
                                  app.doScript("main()", ScriptLanguage.javascript, undefined, UndoModes.ENTIRE_SCRIPT, "FindReplace! …");
                                  
                                  
                                  app.scriptPreferences.enableRedraw = redraw;  
                                  
                                  
                                  function main()     
                                      {
                                          var myDoc = app.activeDocument,
                                          FindWhat = "@.+?#",  // The 2 glyphes are "@" and "#"!
                                          ReplaceBy = "Yes we can!",
                                          CharStyle = "Red";
                                          
                                          app.findGrepPreferences = app.changeGrepPreferences = null;
                                          app.findGrepPreferences.findWhat = FindWhat;
                                          myFound = myDoc.findGrep();
                                          var Counter = myFound.length;
                                          while (Counter--) {
                                              app.findGrepPreferences.findWhat = FindWhat;
                                              myFound = myDoc.findGrep();
                                              var F = myFound.length;
                                              for ( var f = 0; f < F; f++ ) if ( myFound[f].characters[0].baseline !== myFound[f].characters[1].baseline ) myFound[f].contents = "@" + ReplaceBy + "#";
                                          }
                                          app.findGrepPreferences = app.changeGrepPreferences = null;
                                          app.findGrepPreferences.findWhat = ReplaceBy;
                                          app.changeGrepPreferences.appliedCharacterStyle = CharStyle;
                                          FinalCounter = myDoc.changeGrep();
                                          app.findGrepPreferences = app.changeGrepPreferences = null;
                                          
                                          alert( "Treated: " + FinalCounter.length + "!\r(^/)  ;-)")
                                  
                                  
                                      }
                                  

                                   

                                  To be used:

                                   

                                  Capture d’écran 2017-03-13 à 22.29.57.png

                                   

                                  (^/)

                                  • 14. Re: InDesign Script
                                    thaero17058 Level 1

                                    Thanks