1 2 Previous Next 76 Replies Latest reply on Nov 24, 2009 1:39 AM by Kasyan Servetsky

    FindChangeByList script

    davidbillet

      I'm trying to use this pre-made script in CS4, and I customized the accompanying .txt file with all our Find-and Replace needs, but when I actually try to the run the script on a document, the following error message comes up:

       

      Error Number: 23

      Error String: does not have a value

      File: [name and location of jsx file follows]

      Line: 159

      Source: app.doScript(myString, ScriptLanguage.javascript);

       

      Anyone know how to get past this? It's very hard to see what Line 159 in the script file has to do with anything.

       

       

       

      Thanks.

        • 1. Re: FindChangeByList script
          Dave Saunders Level 4

          Hi David,

           

          That error indicates that there is an error in the script in myString which the script you're running has assembled (from the information in your customized .txt file).

           

          Can you tell if any of your searches were executed? That would give a clue as to how far the script progressed before hitting the error.

           

          Alternatively, post your .txt file here and let us see if we can help.

           

          Dave

          • 2. Re: FindChangeByList script
            davidbillet Level 1

            Thanks. No changes were made. Here is the contents of the text file.

             

            //FindChangeList.txt
            //Data file for use with the FindChangeByList.jsx script for InCopy CS4.
            //
            //This data file is tab-delimited, with carriage returns separating records.
            //
            //The format of each record in the file is:
            //findType<tab>findProperties<tab>changeProperties<tab>findChangeOptions<tab>description
            //
            //Where:
            //<tab> is a tab character
            //findType is "text", "grep", or "glyph" (this sets the type of find/change operation to use).
            //findProperties is a properties record (as text) of the find preferences.
            //changeProperties is a properties record (as text) of the change preferences.
            //findChangeOptions is a properties record (as text) of the find/change options.
            //description is a description of the find/change operation
            //
            //Very simple example:
            //text    {findWhat:"--"}    {changeTo:"^_"}    {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false}    Find all double dashes and replace with an em dash.
            //
            //More complex example:
            //text    {findWhat:"^9^9.^9^9"}    {appliedCharacterStyle:"price"}    {include footnotes:true, include master pages:true, include hidden layers:true, whole word:false}    Find $10.00 to $99.99 and apply the character style "price".
            //
            //All InCopy search metacharacters are allowed in the "findWhat" and "changeTo" properties.
            //
            grep    {findWhat:"  +"}    {changeTo:" "}    {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false}    Find all double spaces and replace with single spaces.
            grep    {findWhat:"\r "}    {changeTo:"\r"}    {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false}    Find all returns followed by a space And replace with single returns.
            grep    {findWhat:" \r"}    {changeTo:"\r"}    {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false}    Find all returns followed by a space and replace with single returns.
            text    {findWhat:" - "}    {changeTo:"^="}    {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false}    Find all space-dash-space and replace with an en dash.
            text    {findWhat:"--"}        {changeTo:"^_"}    {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false}    Find all dash-dash and replace with an em dash.
            text    {findWhat:" -- "}    {changeTo:"^_"}    {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false}    Find all space dash-dash space and replace with an em dash.
            text    {findWhat:" ^_ "}    {changeTo:"^_"}    {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false}    Find all space em dash space and replace with an em dash.
            text    {findWhat:"0^]s"}    {changeTo:"0s"}    {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false}    Find all 0 apostrophe s and replace with 0s.
            text    {findWhat:"^e"}        {changeTo:".^<.^<."}    {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false}    Find all ellipses and replace with consecutive period thin space thin spaces.

            • 3. Re: FindChangeByList script
              Kasyan Servetsky Level 5

              Here is a working version, I tested it on CS3 for PC, hope it works on CS4 as well.

              http://www.kasyan.ho.com.ua/downloads/FindChangeList.txt

              P.S. Make sure to download it – don't copy-paste

               

              Kasyan

              • 4. Re: FindChangeByList script
                Olav Martin Kvern Level 3

                Hi davebillet,

                 

                At a glance, your FindChangeList.txt file looks fine, so I'd suspect either line end characters or missing/extra tab characters. Kasyan, was that the problem? (And thanks for helping, Kasyan and Dave!)

                 

                Thanks,

                 

                Ole

                • 5. Re: FindChangeByList script
                  Kasyan Servetsky Level 5

                  Hi Ole,


                  Two lines contained superfluous tabs after find what: Find all dash-dash and replace with an em dash and Find all ellipses and replace with consecutive period thin space thin spaces.

                  The "Find all returns followed by a space And replace with single returns" line was repeated twice.


                  But I’ve found another problem with this script: the following line in the comments shows incorrect example of how to find a text and apply character style "price" to it.

                  //text     {findWhat:"^9^9.^9^9"}     {appliedCharacterStyle:"price"}     {include footnotes:true, include master pages:true, include hidden layers:true, whole word:false}     Find $10.00 to $99.99 and apply the character style "price".

                   

                  A correct reference to the character style should be app.activeDocument.characterStyles.itemByName("price") or app.activeDocument.characterStyles.item("price").

                  I was asked about applying character style by this script twice for last three weeks. When I was asked it for the first time I tried to apply the syntax suggested in the comments, but the script threw an error and stopped. So I reported that it’s impossible to do and wrote my own script. But when I told David about that, he pointed me out to an article in InDesign Magazine: downloads.indesignmag.com/supportfiles/InDesign_Magazine_Issue8_Excerpt.pdf (See page 48). So I decided to sort it out. The article is about the TextCleanup.jsx script for CS2, which is a previous version of FindChangeByList.jsx. But the example given in it is incorrect as well. I think there is the same problem with the version for CS4 too.

                  For the script to work we should use the syntax from OMV, this is obvious for us scripters. But how ordinary people should know this? May be I should create a web-page on my site explaining this?

                   

                  I am thinking on creating a new, more complex search-replace script. Actually I've already started to write it. The idea is as follows:

                  When a user runs the script a floating panel with 3 buttons appears.

                  Instead of writing tab delimited mumbo jumbo strings, user runs a sample query which is undone automatically by the script (button 1).

                  Then he adds description and saves the chosen settings to a text file (button 2).

                  Finally he runs a series search-replace operations. The script reads all saved files and loops thru each saved settings (button 3).

                  But I am not sure if anybody is interested in it.

                   

                  Kasyan


                   

                  • 6. Re: FindChangeByList script
                    Olav Martin Kvern Level 3

                    Hi Kasyan,

                     

                    You're right--the example shown in the comments is wrong. I've been meaning to fix it for some time now.

                     

                    I think that the next version of the script will use the user's own saved Find/Change operations, rather than the text file. It's a very popular script, but it can certainly be made better.

                     

                    Thanks,

                     

                    Ole

                    • 7. Re: FindChangeByList script
                      Kasyan Servetsky Level 5

                      Ole,

                       

                      Recently I watched your videocast on AdobeTV — I am a graphic designer and illustrator by education too.

                      • 8. Re: FindChangeByList script
                        Olav Martin Kvern Level 3

                        Hi Kasyan,

                         

                        I had no idea that was there....:-)

                         

                        I think that was one of my worst presentations, ever. But a few people seemed to get it, anyway.

                         

                        Thanks,

                         

                        Ole

                        • 9. Re: FindChangeByList script
                          Aevee

                          Hi,

                           

                          This is exactly I am looking for, a simple find/replace script but when I try to run your script it has a problem with the very first curly bracket right after the word 'grep'...it says at the left bottom: 'Expected: ;'

                          It is driving me crazy, I am not familiar with script writing and I have no clue what is wrong. Any idea?

                           

                          Thank you!

                          • 10. Re: FindChangeByList script
                            Kasyan Servetsky Level 5

                            This script is not my, but pre-installed with InDesign. Most probably there's some error in FindChangeList.txt file that accompanies the script. Have you changed it?

                            Yesterday I wrote my own script which saves queries and then runs them in sequence. There is no need to meddle with FindChangeList.txt, finding out how to write correct settings. I am going to post it on my site if anybody is interested. But so far it is not completely tested and supports only text search-replace operations.

                             

                            Kasyan

                            • 11. Re: FindChangeByList script
                              Aevee Level 1

                              I tried the script found here, I tried the one comes with ID (I haven't changed it)...none of them works. I found an other topic where someone had the same issue and Olav replied and suspected it was something to do with CS4 (I'm using ID CS4, Windows XP) but then it went private.

                              I have to do lots of find/replace and GREP all the time and thought a script would save me time so I would be definitely interested the script you have written, I might find some useful things in it which will help to write mine.

                               

                              Thanks.  

                              • 12. Re: FindChangeByList script
                                Kasyan Servetsky Level 5

                                I'll post it later – may be tomorrow morning.

                                • 13. Re: FindChangeByList script
                                  Aevee Level 1

                                  Fabulous!

                                  • 14. Re: FindChangeByList script
                                    littlemookie

                                    Hey man,

                                     

                                    I had something similar recently and it turned out to be a sligh 'space' in the middle of the 'tabs' needed to seperate the values in the acutal list.

                                     

                                    Not sure if you have the same problem, but might be worth checking anyway.

                                     

                                    Adios!

                                    • 15. Re: FindChangeByList script
                                      Kasyan Servetsky Level 5

                                      What search-replace operations do you want to perform? Describe what you type manually into Find/Change dialog. Or make screenshots and send them to me – I'll test it when time permits.

                                      • 16. Re: FindChangeByList script
                                        Aevee Level 1

                                        Find and Replace text would be for example:

                                         

                                        <\#165><\#9>           change to: <0x2022>^t

                                         

                                        and a GREP:

                                         

                                        (<B>)(.+?)(<B>)            change to: <ct:65 Bold>$2<ct:>

                                         

                                        I use Find and Replace and GREP to convert textfiles for Quark into textfiles for InDesign hence a script that does it with one click would be awsome! So if I had a basic script that I can extend it would be more than appreciated...

                                        • 17. Re: FindChangeByList script
                                          Olav Martin Kvern Level 3

                                          Hi aevee,

                                           

                                          Something like this:

                                           

                                          //Clear find/change text preferences
                                          app.findTextPreferences = NothingEnum.nothing;
                                          app.changeTextPreferences = NothingEnum.nothing;
                                          //Set up the find/change strings (note "escaped" backslash characters).
                                          app.findTextPreferences.findWhat = "<\\#165><\\#9>";
                                          app.changeTextPreferences.changeTo = "<0x2022>^t";
                                          //Change the text.
                                          app.documents.item(0).changeText();
                                          //Clear find/change text preferences.
                                          app.findTextPreferences = NothingEnum.nothing;
                                          app.changeTextPreferences = NothingEnum.nothing;
                                          //Clear find/change grep preferences.
                                          app.findGrepPreferences = NothingEnum.nothing;
                                          app.changeGrepPreferences = NothingEnum.nothing;
                                          //Set up the grep find/change
                                          app.findGrepPreferences.findWhat = "(<B>)(.+?)(<B>)";
                                          app.changeGrepPreferences.changeTo = "<ct:65 Bold>$2<ct:>";
                                          //Change the text.
                                          app.documents.item(0).changeGrep();
                                          app.findGrepPreferences = NothingEnum.nothing;
                                          app.changeGrepPreferences = NothingEnum.nothing;


                                          Thanks,

                                           

                                          Ole

                                          • 18. Re: FindChangeByList script
                                            Aevee Level 1

                                            Fantastic! Thank you ever so much Olav! You've made my day...

                                             

                                            And a very last question...if I have a list of GREPs let's say, do I have to 'clear find/change grep preferences' first every time before setting up a new one?

                                             

                                            Thank you again!!!!!!!!!!

                                            • 20. Re: FindChangeByList script
                                              Aevee Level 1

                                              Splendid! Very clever. Exactly what I needed to control the formats as well...

                                               

                                              Thank you, thank you, thank you Kasyan! 

                                              • 21. Re: FindChangeByList script
                                                Kasyan Servetsky Level 5

                                                I wrote it the day before yesterday, so it's not thoroughly tested yet. Let me know how it works. BTW, I am open to any suggestions as to how improve it.

                                                • 22. Re: FindChangeByList script
                                                  Aevee Level 1

                                                  I followed your instructions and it worked fine.

                                                   

                                                  What I really like about it that you can change it very easily by deleting/renaming/rearranging the textfiles the script creates instead of going through a whole long script amending it all the time. I haven't tried yet but I guess you can create lots of different  'Queries' by renaming the folders. Genius!  If it supports GREP as well it will be extremely useful for many of us I believe (it already is but then....can't wait!).

                                                   

                                                  Thank you again!

                                                  • 23. Re: FindChangeByList script
                                                    tynan Level 1

                                                    Hey Kaysan, I'm new to all this but know your name already, you're doing fanatstic stuff

                                                     

                                                    I've just found your link script on your home page and if it works it's going to be a lifesaver for me

                                                     

                                                    This new one looks excellent too, If it runs GREP searches as well that's be amazing, I've got a javascript that runs a load of stuff but it doesn;t like the more complex GREP searches even though they run pefectly within Indesign's Find/Change queries

                                                     

                                                    Thanks

                                                    • 24. Re: FindChangeByList script
                                                      tynan Level 1

                                                      +1  to Kasyan doing fantstic work, I've used a few of his scripts in the project to fully format a text file in a single pass, I'm now using the script from his site that captures an ID Find.Change search for the FindChangeByList.txt

                                                       

                                                      brilliant

                                                       

                                                      The only thing left that I can;t get to run in the javascript FindChangeByList is the URL search, it runs fine in ID but won't as partof the script, I've read sundry comments saying more complex grep searched won't run as part of the FindChangeByList script

                                                       

                                                      It really is the last thing I need to get running before it's a shining masterpiece

                                                       

                                                      This is what I have, any ideas from the gurus? Many thanks to Kasyan, again

                                                       

                                                      grep    {findWhat:"(?i)(http|ftp|www)(\\S+)|(\\S+) (\\.gov|\\.us|\\.co\\.uk|\\.net|\\.com|\\.edu|\\.org|\\.org/|\\.biz)"}    {appliedCharacterStyle:"www."}

                                                      • 25. Re: FindChangeByList script
                                                        [Jongware] Most Valuable Participant

                                                        Can you paste the GREP search expression that works in InDesign?

                                                        It seems to me there should be even more backslashes in the script version (every singe backslash needs doubling), but it's kinda hard to see which one(s).

                                                        • 26. Re: FindChangeByList script
                                                          tynan Level 1

                                                          Hi fella and thanks for the quick response

                                                           

                                                          (?i)(http|ftp|www)(\S+)|(\S+) (\.gov|\.us|\.net|\.com|\.edu|\.org|\.org/\.biz)

                                                           

                                                          that works, at least for the things we need to find

                                                           

                                                          Thanks

                                                          Tynan

                                                          • 27. Re: FindChangeByList script
                                                            [Jongware] Most Valuable Participant

                                                            Okay, I think I see it. You did a good job on doubling the backslashes, except for this one:

                                                             

                                                            .org/|\\.biz

                                                             

                                                            The pipe should not be there.

                                                             

                                                            (at least, I hope it's this simple -- not being at the right computer, can't check)

                                                            • 28. Re: FindChangeByList script
                                                              tynan Level 1

                                                              I think that's correct though, I added that bit to capture instances where the search was missing the trailing '/' of a URL

                                                               

                                                              The pipe seperates it from the next match, '.biz'

                                                               

                                                              I've tried an awful lot of combinations and massive simplifications to try and make it work, it simply doesn't seem to want to work

                                                               

                                                              Granted my scripting is rank beginner level at best so I could be making any mistake

                                                               

                                                              I captures the search using the script from Kasyan's site so that should be the FindChangeByList equivalent of the working script in ID

                                                               

                                                              If you're keen and feeling helpful I'd be very grateful indeed if you could try the ID Find/Cange grep search in ID3, see that it works and then replicate it in FindChangeByList

                                                               

                                                              I strongly suspect that the script plain won;t run that much grep in one line which is an awful shame if true

                                                               

                                                              I will try the pipe change though, just in case and seeing as you know 10000 times more about this than me

                                                               

                                                              Thanks

                                                              Tynan

                                                              • 29. Re: FindChangeByList script
                                                                [Jongware] Most Valuable Participant

                                                                It sounds you are trying the right things. Unfortunately, my home CS doesn't come with GREP ...

                                                                 

                                                                FindChangeByList has some problems with correct formatting of the lines (I think that's discussed in this same thread). Perhaps that's why it fails.

                                                                 

                                                                I hope someone else comes up with more ideas.

                                                                • 30. Re: FindChangeByList script
                                                                  Kasyan Servetsky Level 5

                                                                  Hi Tynan,

                                                                   

                                                                  The following line works for me:

                                                                  grep    {findWhat:"(?i)(http|ftp|www)(\\S+)|(\\S+) (\\.gov|\\.us|\\.net|\\.com|\\.edu|\\.org/\\.biz)"}    {appliedCharacterStyle:"www."}    {includeLockedStoriesForFind:false, includeLockedLayersForFind:false, includeHiddenLayers:false, includeMasterPages:false, includeFootnotes:true}    //Comment

                                                                   

                                                                  I tested it on CS3 for Mac. I used the version of the script for CS4 – It seems to be more reliable. I've attached both files: jsx and txt.

                                                                  You typed \.org| twice, so I removed one of them.

                                                                   

                                                                   

                                                                  Kasyan

                                                                  • 31. Re: FindChangeByList script
                                                                    tynan Level 1

                                                                    I'll test that sharpish, thanks in advance, I'm going to get a plaque put in our office to you!

                                                                     

                                                                    CS4 script will run in CS3? The galling thing is we have CS4 installed but are banned from using it to keep us in line with co-publishers, most of whom reset our books into bloody Quark v6 anyway

                                                                     

                                                                    Not important but that extra org was in there to catch the ones with a trailing backslash/forwardslash

                                                                     

                                                                    Thanks again gents, javascript is wonderful stuff and the scripts shared out have ben excellent, the scripts from the Kasyan site are putting in hours and hours of work every single day here

                                                                     

                                                                    bless you

                                                                     

                                                                    Tynan

                                                                    • 32. Re: FindChangeByList script
                                                                      Kasyan Servetsky Level 5

                                                                      CS4 script will run in CS3?

                                                                      Yes, it works.

                                                                      • 33. Re: FindChangeByList script
                                                                        tynan Level 1

                                                                        not working ...

                                                                         

                                                                        I've tried with the exact cs4 and the txt file you attached but it finds nothing, not even the simplest 'www.tynan.com' type text

                                                                         

                                                                        Everthing else works lovely but this one search, what can I be doing differently?

                                                                         

                                                                        So close and so far, this is starting to really hack me off

                                                                         

                                                                        time to start trying on other macs here I suppose

                                                                        • 34. Re: FindChangeByList script
                                                                          Kasyan Servetsky Level 5

                                                                          Did you run the CS3 version of the script before that? I noticed that CS3 version often spoils things with GREP search-replace. Try to restart ID and run only the CS4 version again.

                                                                          • 35. Re: FindChangeByList script
                                                                            tynan Level 1

                                                                            yes I did and I should have known thaI'm very very busy and a bit frazzled

                                                                             

                                                                            I'll try that right nowI

                                                                            • 36. Re: FindChangeByList script
                                                                              tynan Level 1

                                                                              Winner!

                                                                               

                                                                              It works following the restart

                                                                               

                                                                              Thank-you so much, this will save us so much time here!

                                                                               

                                                                              Thanks for sticking with it and your prompt attention.

                                                                               

                                                                              That's three bits of your scripting I'm using routinely now to process hundreds of books each with 50 seperate chapters, I can;t imagine doing ti any other way

                                                                               

                                                                              Thanks again

                                                                              Tynan

                                                                              • 37. Re: FindChangeByList script
                                                                                Sara Peroni Level 1

                                                                                Hi,

                                                                                I must  insert a new query in this example.

                                                                                 

                                                                                If I save the query by indesign interface obtain the file .xml with the preference like this:

                                                                                 

                                                                                <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
                                                                                <Query>
                                                                                <Header>
                                                                                <Version major="5" minor="1">
                                                                                </Version>
                                                                                <Application value="Adobe InDesign">
                                                                                </Application>
                                                                                <QueryType value="Grep" qid="1">
                                                                                </QueryType>
                                                                                </Header>
                                                                                <Description>
                                                                                <FindExpression value=".{20,}">
                                                                                </FindExpression>
                                                                                <ReplaceExpression value="">
                                                                                </ReplaceExpression>
                                                                                <FindChangeOptions>
                                                                                <IncludeLockedLayers value="0">
                                                                                </IncludeLockedLayers>
                                                                                <IncludeLockedStories value="0">
                                                                                </IncludeLockedStories>
                                                                                <IncludeMasterPages value="0">
                                                                                </IncludeMasterPages>
                                                                                <IncludeHiddenLayers value="0">
                                                                                </IncludeHiddenLayers>
                                                                                <IncludeFootnotes value="1">
                                                                                </IncludeFootnotes>
                                                                                <KanaSensitive value="1">
                                                                                </KanaSensitive>
                                                                                <WidthSensitive value="1">
                                                                                </WidthSensitive>
                                                                                </FindChangeOptions>
                                                                                <FindFormatSettings>
                                                                                <TextAttribute type="cstyle" value="_M">
                                                                                </TextAttribute>
                                                                                </FindFormatSettings>
                                                                                <ReplaceFormatSettings>
                                                                                <TextAttribute cls_id="6948" value="0">
                                                                                </TextAttribute>
                                                                                <TextAttribute type="changecondmode" value="0">
                                                                                </TextAttribute>
                                                                                </ReplaceFormatSettings>
                                                                                </Description>
                                                                                </Query>

                                                                                 


                                                                                How can insert this in the file FindChandgeList.txt for execute by script?

                                                                                 

                                                                                Thanks

                                                                                 

                                                                                Sara

                                                                                • 38. Re: FindChangeByList script
                                                                                  Kasyan Servetsky Level 5

                                                                                  You can't do this. Use this script to record settings from Text and GREP tabs, then copy and paste them to FindChandgeList.txt file.

                                                                                  http://www.kasyan.ho.com.ua/downloads/RecordFindChange_CS3_Kas.zip

                                                                                  • 39. Re: FindChangeByList script
                                                                                    Sara Peroni Level 1
                                                                                    I do not know how to thank you!
                                                                                    The script work very well!

                                                                                    Sara
                                                                                    1 2 Previous Next