9 Replies Latest reply on Mar 14, 2010 7:45 AM by Ola K

    Search on all documents [CS3] [Javascript]

    Ola K Level 1

      Hi guys,

       

      Does any of you know how to perform a search on all documents?

       

      I've tried this line, which did not work:

      foundItems = app.documents.findGrep ();

       

      and this line, which bugged my script:

      foundItems = app.documents.itemByRange(0,-1).findGrep ();

       

      What is the correct way to do this?

       

      Thanks,

      Ola

        • 1. Re: Search on all documents [CS3] [Javascript]
          Harbs. Level 6

          app.findGrep();

           

          Harbs

          • 2. Re: Search on all documents [CS3] [Javascript]
            Ola K Level 1

            I tried it as well, and per what I saw it doesn't necessarily search all documents.

             

            Is there a way to tell InDesign to definitely search all documents?

             

            Ola

            • 3. Re: Search on all documents [CS3] [Javascript]
              [Jongware] Most Valuable Participant

              You are aware it only searches in those documents that are actually open in InDesign? (Just checking.)

               

              Compare with this:

               

              var foundIn = 0;
              var numbfounded = 0;
              for (doc=0; doc<app.documents.length; doc++)
              {
                 foundlist = app.documents[doc].findGrep();
                 if (foundlist.length > 0)
                   foundIn++;
                 numbfounded += foundlist.length;
              }
              
              alert (numbfounded+" items found in "+foundIn+" documents");
              
              • 4. Re: Search on all documents [CS3] [Javascript]
                Ola K Level 1

                Yes, I am aware... This datum was so obvious to me that I didn't even bother with writing it in the message. But I guess sometimes you need to write the obvious

                 

                Now, that code you wrote can lead to a solution, I am going to look into this.

                 

                thanks,

                Ola

                • 5. Re: Search on all documents [CS3] [Javascript]
                  [Jongware] Most Valuable Participant

                  Well, my code wasn't as much intended to be a solution, but rather a means of comparing the number of found items against app.findGrep. There is no reason (... I think) app.findGrep would fail where app.document[x].findGrep would work fine.

                   

                  How did you see your original solution didn't find everything you thought it would?

                  • 6. Re: Search on all documents [CS3] [Javascript]
                    Ola K Level 1

                    Hi,

                     

                    Sorry for the late response, I had some other rush project coming in.

                     

                    Anyhow, I am not sure I fully got your question, but here is (hopefully) the answer:

                     

                    app.findGrep () works well. However, it usually searches the current document only. In some cases it does search all open documents. I did not find any certain way to guarantee where it would search.

                     

                    So my original solution might have worked well, and might have not, and I cannot really "just hope" it will be ok, I want to find a definite way to tell InDesign to search all open documents.

                     

                    Do you know of such a way?

                     

                    Ola

                    • 7. Re: Search on all documents [CS3] [Javascript]
                      Ola K Level 1

                      An update:

                       

                      So I did a test on some dummy files and these were the results:

                       

                      app.findGrep ()

                      searches in all open documents. If you have only one open document, it obviously searches only there.


                      app.activeDocument.findGrep ()

                      searches in the active document only, regradless of how many documents you have open.


                      app.documents[0].findGrep ()

                      searches in the active document only, regradless of how many documents you have open.

                       

                      Now, this should explain why sometimes "app.findGrep ()" searches in all documents and sometimes not. It depended on how many documents I have open!

                       

                      Well, I hope this is the solution, I am going to try this on the real files now.

                       

                      Ola

                      • 8. Re: Search on all documents [CS3] [Javascript]
                        [Jongware] Most Valuable Participant

                        Your findings describe exactly what's in the Help ... It has been the standard behavior of InDesign ever since v1.0 -- searching "All Documents" only works on those that are, well, open in the program. I'll grant you this: despite the description, it's not really "all documents" ... (on your hard disk, on the internet, on external CDs... etc.)

                         

                        For what it's worth, I have several scripts that operate on Books, sometimes consisting of more than 20 individual files. The scripts start with opening all documents, do their stuff, then closes them again. No sweat. It's not even worth the trouble of 'checking if the document is already opened'.

                        • 9. Re: Search on all documents [CS3] [Javascript]
                          Ola K Level 1

                          Yeah, that is the best approach in most cases.

                           

                          Ola