33 Replies Latest reply on Jul 12, 2009 4:48 PM by flaming1

    Inconsistent behaviour with find/change Applescript

    flaming1 Level 2

      Hi

       

      I am trying to add additional find/change queries to the script by copying and pasting existing queries in the FindChangeList.txt file, and then changing the variables that are being searched/changed. I am having mixed success though - sometimes I add a new query and it disables one of the existing queries, other times I add a new query and it just doesn't work.

       

      Is it something to do with the copying/pasting of the items, or are there some rules around what order the items have to be in?

       

      For example, this works fine:

       

      text {find what:"Mobile"} {change to:"M"} {include footnotes:true, include master pages:true, include hidden layers:true, whole word:false} Find Mobile and replace with M.

       

      Yet this, immediately before it, doesn't?

       

      text {find what:"Business"} {change to:"B"} {include footnotes:true, include master pages:true, include hidden layers:true, whole word:false} Find Business and replace with B.

       

      One is just a copy of the other, so what's the difference?

       

      I love this script and the time it saves me, but the more I tinker with it, the more it doesn't seem to work consistently.

       

      Any suggestions would be appreciated.

       

      Cheers

      Steve

        • 1. Re: Inconsistent behaviour with find/change Applescript
          Kasyan Servetsky Level 5

          Hi Steve,

           

          These lines work fine for JS version of the script:

           

          text  {findWhat:"Business"}   {changeTo:"B"}    {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:true}     Find Business and replace with B

          text  {findWhat:"Mobile"}     {changeTo:"M"}    {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:true}     Find Mobile and replace with M.

           

          I can't check it on Mac right now.

           

          As an alternative you can use my script:

          http://kasyan.ho.com.ua/find_change_by_queries.html

           

          Kasyan

          • 2. Re: Inconsistent behaviour with find/change Applescript
            flaming1 Level 2

            Thanks for looking into my issue Kasyan.

             

            I know that what I had done was correct for syntax, and that it should work, but as soon as I added something, or modified any other part of the script. Then a query that had originally worked, just stopped working - seemingly at random. Sometimes when I add a new query it works, sometimes it doesn't, but the syntax is always exactly the same.

             

            Just by rearranging the order of the queries in the script I get several that then stop working.

             

            This seems to be the focus of the problem - is it that the queries have to be in a particular order, or is it that copying and pasting creates an unworkable script? I have also tried rekeying parts of the script, rather than copying and pasting, but with similar results.

             

            In my experience, some of the other sample JS scripts are more prone to failing than the AS ones. That is why I was starting with the AS version. For example the AddGuides script fails frequently for me if I use the JS version, but consistently works if I use the AS one.

             

            I'll have a look at your script and se if that helps.

             

            Steve

            • 3. Re: Inconsistent behaviour with find/change Applescript
              flaming1 Level 2

              Further to my feeling that it has something to do with copying and pasting, or the order in which queries are read I have tested each line of the following individually and they all work perfectly as single line queries. I have re-entered the content several times in varying orders, but I cannot find anything consistent that makes elements of it just stop working.

               

              At present the following successfully runs all but the first and last queries? Is there some syntax that I need to place before the first query and/or after the last query to get them to trigger. Or is there something that needs to be placed at the end of each query?

               

              I am using TextEdit to edit the file and I have it formatted as Plain Text.

               

              I have tried again with re-ordering the lines after they are entered to see if that works but the broken ones stay broken and then after a few changes other lines cease to function.

               

              It's very frustrating with it 'almost' working as the script has the potential to save a lot of time on a few jobs that I do regularly.

               

              grep {find what:"  +"} {change to:" "} {include footnotes:true, include master pages:true, include hidden layers:true, whole word:true} Find all double spaces and replace with single spaces.

              text {find what:"Business"} {change to:"B"} {include footnotes:true, include master pages:true, include hidden layers:true, whole word:false} Find all returns followed by a space and replace with single returns.

              text {find what:"Mobile"} {change to:"M"} {include footnotes:true, include master pages:true, include hidden layers:true, whole word:false} Find all double tab characters and replace with single tab characters.

              text {find what:"Mobile"} {change to:"M"} {include footnotes:true, include master pages:true, include hidden layers:true, whole word:false} Find all double tab characters and replace with single tab characters.

              text {find what:"Home"} {change to:"H"} {include footnotes:true, include master pages:true, include hidden layers:true, whole word:false} Find all returns followed by a tab character and replace with single returns.

              text {find what:"^p"} {change to:"^n"} {include footnotes:true, include master pages:true, include hidden layers:true, whole word:false} Replace para returns with forced line break for styles to allow for nested paragraph style.

              text {find what:": "} {change to:"^t"} {include footnotes:true, include master pages:true, include hidden layers:true, whole word:false} Find colon followed by a space and replace with tab.

              text {find what:"^?"} {applied paragraph style:"NAMES2"} {include footnotes:true, include master pages:true, include hidden layers:true, whole word:false} Applies paragraph style.

               

              Any suggestions?

               

              Steve

              • 4. Re: Inconsistent behaviour with find/change Applescript
                [Jongware] Most Valuable Participant

                The input file is highly sensitive to tabs. Are there single tabs between each item, rather than one or more spaces?

                • 5. Re: Inconsistent behaviour with find/change Applescript
                  Kasyan Servetsky Level 5

                  grep {find what:"  +"} {change to:" "} {include footnotes:true, include master pages:true, include hidden layers:true, whole word:true} Find all double spaces and replace with single spaces.

                   

                  GREP doesn't have whole word parameter -- this is a mistake.

                   

                  I would check the script in ScriptDebugger: e.g. set break points after defining find/change text preferences, find/change grep preferences, and find/change text/grep options, and see if any error occurs. Most probably, there is some typo: spaces instead a tab, two tabs instead of one, etc.

                   

                  Kasyan

                  • 6. Re: Inconsistent behaviour with find/change Applescript
                    flaming1 Level 2

                    Thanks for the input guys, but as I said, each line works perfectly when they are used individually so it is not a stray tab or space and the syntax is definitely correct.

                     

                    I do appreciate the suggestions regardless, and I'll keep plugging away at it until it works, but I think what is missing from the script is just the right amount of luck

                     

                    I nearly had it all working last night, but then in trying to just amend the search query it broke again.

                    • 7. Re: Inconsistent behaviour with find/change Applescript
                      Dave Saunders Level 4

                      I notice that at no point have you mentioned which version of InDesign you're using. I seem to recall that the original version of this script that shipped with CS3 had a serious bug in it that could cause exactly the kinds of problem you're describing.

                       

                      If you are indeed working with the original shipped CS3 version, try visiting this page:

                       

                      http://www.adobe.com/products/indesign/scripting/

                       

                      Click the Scripting Resources tab and then scroll down to the CS3 area to get the updated version of the CS3 scripts.

                       

                      Dave

                      • 8. Re: Inconsistent behaviour with find/change Applescript
                        Mary Posner Level 3

                        I've had the same thing happen, that it only recognizes the first line of code. I think it has something to do with how the text file is saved, that it's somehow not recognizing the return as the end of the first line, but I don't remember how it has to be saved to get it to work for more than one find/change.

                        • 9. Re: Inconsistent behaviour with find/change Applescript
                          flaming1 Level 2

                          I am definitely using the newest version of the script. I re-downloaded it just to check, but the problem definitely still persists. I am using CS3 on an Intel iMac.

                           

                          I think Mary is on to the real problem and that is, it seems to not be recognising the returns between lines. If you open the FindChangeList.txt file in TextEdit and put your cursor at the start of any line, you will find that it takes two presses of the Return key before anything moves.

                           

                          This seems to be where the problem lies - so what is the special character (invisible?) that needs to be at the start of each line, or does it mean that the file needs to be edited in something other than TextEdit to function?

                           

                          I have the script doing some very useful and time saving stuff, but I'd really like to be able to combine all the individual lines into the one file and still have it work!

                           

                          Thanks again for everybody's input so far.

                           

                          Steve

                          • 10. Re: Inconsistent behaviour with find/change Applescript
                            Harbs. Level 6

                            For plain text files, you should really use TextWrangler http://www.barebones.com/products/textwrangler/

                              (or equivalent)...

                             

                            Harbs

                            • 11. Re: Inconsistent behaviour with find/change Applescript
                              Kasyan Servetsky Level 5

                              There is something wrong with AS version of the script -- I tested it in ScriptDebugger an it reads only 2 lines for me. I recommend you to use JS version. (See attached files) I took it from CS4, but it works in CS3 as well. I made some corrections to the file you had posted in post#3 and it works for me.

                               

                              Kasyan

                              • 12. Re: Inconsistent behaviour with find/change Applescript
                                Kasyan Servetsky Level 5

                                 

                                There is something wrong with AS version of the script – try to use JS version instead. I made some corrections to your post #3 – I found a few mistakes in it. See the attached file – it works for me

                                 

                                 

                                Kasyan

                                 

                                P.S. I'm sorry for double posting; there's some troubles with this forum.

                                • 13. Re: Inconsistent behaviour with find/change Applescript
                                  Mary Posner Level 3

                                  Thanks, Kasyan & Harbs,

                                   

                                  I usually use Applescript, but in this case I am using the JS version -- it's the text file that isn't playing nice. Thanks for the CS4 version. I couldn't find the CS3 sample scripts on the Adobe page Dave linked to.

                                   

                                  I thought I had tried saving the text file through TextWrangler since I wasn't having any luck with TextEdit, but maybe not -- it's been awhile since I tried. I'll give that a try next time I need to use this.

                                   

                                  Thanks again, always, for everybody's knowledgeable assistance!

                                   

                                  Mary

                                  • 14. Re: Inconsistent behaviour with find/change Applescript
                                    Larry G. Schneider Adobe Community Professional & MVP

                                    Make sure your saved file is plain text, not RTF. One of the two defaults to RTF but I don't remember which.

                                    • 15. Re: Inconsistent behaviour with find/change Applescript
                                      flaming1 Level 2

                                      Thanks Harbs - it seems that TextEdit was definitely part of the problem. Since I started using TextWrangler I haven't struck the problem again. It seems that TextEdit's 'plain text' is not very clean. It showed up quite differently when I opened it in TextWrangler.

                                       

                                      I haven't done much more work with it over the last few days, but the initial attempts seem very promising.

                                       

                                      Now, can I add a further query...

                                       

                                      I am able to grep search for multiple figures and replace/change them using the (01|02|03) approach like this:

                                       

                                      grep {find what:"(03|04|06|07|09|021|025|027|029)(\\d{3})(\\d{4})"} {change to:"$1 $2 $3"} {include footnotes:true, include master pages:true, include hidden layers:true, whole word:false} Find phone suffix and redistribute characters.

                                       

                                      And it works just fine, but can I do that with text? I have text that is supplied as, for example, 'Mobile' followed by a tab, as well as 'Mobile' followed by a space. I'd like to be able to search both occurrences and replace with just 'M' followed by a tab, but do I have to do this with multiple text searches?

                                       

                                      Here is what I tried, but with no luck...

                                       

                                      grep {find what:"(Mobile |Mobile\t)"} {change to:"M\t"} {include footnotes:true, include master pages:true, include hidden layers:true, whole word:false} Multiple find with single replace

                                       

                                      I was expecting this to find all occurrences of the the word Mobile, followed by either a space or a tab and replace them with the word 'M' followed by a tab, but nothing happens. I'm not sure whether you can't search multiple words, or whether I have the syntax wrong.

                                       

                                      Steve

                                      • 16. Re: Inconsistent behaviour with find/change Applescript
                                        sstanleyau Level 4

                                        >find all occurrences of the the word Mobile, followed by either a space or a tab

                                         

                                        In that case, search for:

                                         

                                        "Mobile[ \t]"

                                        1 person found this helpful
                                        • 17. Re: Inconsistent behaviour with find/change Applescript
                                          flaming1 Level 2

                                          Thanks, but it's looking like it isn't possible to search for words using grep? I couldn't get that syntax to work either, but then even if I try to grep search just a single word it finds nothing. Perhaps I am misunderstanding or misusing grep...

                                           

                                          Using a text query, rather than grep, will find the single word without any trouble, but I am assuming I need to use grep if I am looking for the multiple variants in one go? Or should I just be using multiple text queries?

                                           

                                          This is what I would use if I did it with multiple text queries - and it works fine - but I would like to be able to do the same with a single grep search.

                                           

                                          text {find what:"Mobile "} {change to:"M^t"} {include footnotes:true, include master pages:true, include hidden layers:true, whole word:false} Find Mobile plus space and make M plus Tab.

                                          text {find what:"Mobile^t"} {change to:"M^t"} {include footnotes:true, include master pages:true, include hidden layers:true, whole word:false} Find Mobile plus tab and make M plus Tab.

                                           

                                          Is it possible to get that done in one grep query?

                                          • 18. Re: Inconsistent behaviour with find/change Applescript
                                            sstanleyau Level 4

                                            > Is it possible to get that done in one grep query?

                                             

                                            That's exactly what "Mobile[ \t]" does -- look for "Mobile" followed by either a space or a tab.

                                            • 19. Re: Inconsistent behaviour with find/change Applescript
                                              [Jongware] Most Valuable Participant

                                              Perhaps the '\t' has to be double escaped -- '\\t'.

                                              1 person found this helpful
                                              • 21. Re: Inconsistent behaviour with find/change Applescript
                                                flaming1 Level 2

                                                OK, so what am I still doing wrong?

                                                 

                                                grep {find what:"Mobile[ \\t]"} {change to:"XX"} {include footnotes:true, include master pages:true, include hidden layers:true, whole word:false} Multiple find to one change

                                                 

                                                This doesn't do anything? As I mentioned earlier, it seems that I am unable to search anything other than numbers with grep.

                                                 

                                                If I change the query to a number...

                                                 

                                                grep {find what:"02[ \\t]"} {change to:"XX"} {include footnotes:true, include master pages:true, include hidden layers:true, whole word:false} Multiple find to one change

                                                 

                                                ...then it works perfectly? 02 followed by a space and 02 followed by a tab are both found and changed.

                                                 

                                                What is it that I need to do to make it work with text as well?

                                                • 22. Re: Inconsistent behaviour with find/change Applescript
                                                  Harbs. Level 6

                                                  Are you sure the text is exactly the same? What happens when you use 

                                                  the Find/Change dialog?

                                                   

                                                  Harbs

                                                  • 23. Re: Inconsistent behaviour with find/change Applescript
                                                    flaming1 Level 2

                                                    Yes, the text is exactly the same in the FindChangeList.txt. The only thing I am doing is substituting '02' for 'Mobile'.

                                                     

                                                    In  the Find/Change dialog the same happens. All occurrences of '02' followed by a space or a tab are found and replaced, yet entering 'Mobile' instead of '02' brings up "cannot find match". A text search of course finds Mobile with no problem at all.

                                                     

                                                    It still seems that grep is unable to search letters, it only works with numbers.

                                                     

                                                    Steve

                                                    • 24. Re: Inconsistent behaviour with find/change Applescript
                                                      Harbs. Level 6

                                                      Hi Steve,

                                                       

                                                      GREP definitely works with letters, and your grep works fine by me. 

                                                      Try manually typing in "Mobile " to see if it finds that. I have a 

                                                      feeling that your text is not encoded properly.

                                                       

                                                      Harbs

                                                      • 25. Re: Inconsistent behaviour with find/change Applescript
                                                        flaming1 Level 2

                                                        Hi Harbs

                                                         

                                                        I'm not sure what you mean by the text not being encoded properly? Are you referring to the FindChangeList text or the text in the Indesign file?

                                                        Whichever one it is, are you able to clarify what it should be encoded as and how I do that.

                                                         

                                                        Thanks

                                                        Steve

                                                        • 26. Re: Inconsistent behaviour with find/change Applescript
                                                          Harbs. Level 6

                                                          I mean in your InDesign file. The GREP works for me, so something is 

                                                          wrong at your end. If you try typing in the text you are searching 

                                                          for, you can see if that works. If not, maybe try trashing your 

                                                          preferences.

                                                           

                                                          Harbs

                                                          • 27. Re: Inconsistent behaviour with find/change Applescript
                                                            flaming1 Level 2

                                                            Thanks for all the suggestions Harbs, but still no luck here.

                                                             

                                                            I have trashed the prefs, started with a new Indesign document, keyed in new sample text, and created a new FindChangeList.txt file from scratch in TextWrangler, yet I am still unable to get it to work. Grep will not do any FindChange operations that involve words. I am now back to only being able to execute one query at a time again as well. The ability to run multiple queries from the one FindChangeList seems to have broken again.

                                                             

                                                            I have also tried it on my second Mac and on a Mac at my work, but with the same, or similar results.

                                                             

                                                            I think with all the responses I have received through this thread that I can be happy that what I am doing should work - ie. I'm doing it correctly - but I'll just have to accept that for whatever reason it just doesn't 'want' to work for me.

                                                             

                                                            Thanks to everyone that has posted here with suggestions. I'll post again if I come across a fix to the problem.

                                                             

                                                            Cheers

                                                            Steve

                                                            • 28. Re: Inconsistent behaviour with find/change Applescript
                                                              Kasyan Servetsky Level 5

                                                              Yesterday I found a script, written by Martin Fisher, which records settings from Text and GREP Find/Change dialogs and saves them to a text file. These saved settings you can copy-paste into your FindChangeList.txt file. But it works with JS version of FindChangeByList script.

                                                              If you are interested, let me know, I'll post it.

                                                               

                                                              Kasyan

                                                              • 29. Re: Inconsistent behaviour with find/change Applescript
                                                                Martin Fischer Level 2

                                                                Hello Kasyan,

                                                                 

                                                                > If you are interested, let me know, I'll post it.

                                                                 

                                                                There is no need to post the script itself.

                                                                The link may be good enough: RecordFindChange_CS3.jsx

                                                                 

                                                                The script isn't originally written by myself.

                                                                It is a modification of Olav Kverns CS2-Script RecordFindChange.jsx that records findChangeText-settings.

                                                                But I have extended it to record also findChangeGrep-settings in CS3 and later.

                                                                 

                                                                Martin

                                                                • 31. Re: Inconsistent behaviour with find/change Applescript
                                                                  flaming1 Level 2

                                                                  I have just found another intriguing twist to the saga.

                                                                   

                                                                  I had the opportunity to try out the script on a brand new Mac, with Indesign CS3 newly installed. I first tried GREP searches for numbers and words within Indesign's own find/change dialog box. Much to my surprise it not only searched numbers successfully, but also words.

                                                                   

                                                                  So I tried running the script. Unfortunately it STILL doesn't work on GREP searches involving words.

                                                                   

                                                                  But here's the twist... after running the script once, Indesign's own find/change dialog box was now unable to GREP search words, in any file.

                                                                   

                                                                  In a nutshell, running the script 'broke' Indesign, and this affected even new documents created after the script was run. It seems there is something inherently bad in the script itself that is causing all these problems. Files were unable to be GREP searched for any words, existing or newly typed, in old or new files. GREP searches on anything else - numbers, punctuation etc still work fine.

                                                                   

                                                                  Trashing Indesign's preferences brings back the functionality within Indesign's find/change on all files, but as soon as the script is run again the functionality disappears and no words are GREP searchable anywhere... until the preferences are trashed again.

                                                                   

                                                                  Does this give anyone any further clues as to what is going wrong? The script seems to be somehow turning off the GREP search function in the preferences file - how I do not understand.

                                                                   

                                                                  This was done using the JS version of FindChangeList.

                                                                  • 32. Re: Inconsistent behaviour with find/change Applescript
                                                                    Kasyan Servetsky Level 5

                                                                    Don't use the version of the script for CS3 — use CS4 version instead (you can download it from post #12).

                                                                    • 33. Re: Inconsistent behaviour with find/change Applescript
                                                                      flaming1 Level 2

                                                                      Thank you Kasyan - that works!

                                                                       

                                                                      I had already downloaded the CS4 version from Adobe and tried that but it didn't work, so I'm not sure what is different here.

                                                                      Regardless, I am now able to get the script to do everything I want so thank you very much, and thanks to everyone else who helped out with advice.

                                                                       

                                                                      Steve