6 Replies Latest reply on Nov 5, 2009 7:54 AM by rpollack-2

    newbee needs suggestions for a search and replace script

    rpollack-2 Level 1

      I can't figure out this scripting stuff. I looked at the scripting guide I downloaded from adobe some time ago. I am not a programmer.

       

      I do not need a script that says "hello world."

       

      I need a script that will do the following:

       

      Search selected text from one point to another. let me explain.

       

      I create a table of contents in InDesign CS4. We separate our book sections by "section". So the TOC looks like:

       

      Section 1

      item one.... 1

      item two... 2-4

      item three... 5

       

      Section 2

      item one... 1-3

      item two... 4-5

      item three... 6

       

      and so forth.

       

      I then manually go in and change the TOC to:

      Section 1

      item one... 1 - 1

      item two... 1 - 2-4

       

      Section 2

      item one... 2 - 1-3

      item two... 2 - 4-5

       

      Where the page reference in the TOC contains the section prefix and the page number provides the page range (if more than one page). Should mention that when I create the TOC I use a place holder in the TOC style set up for the section prefix; that is, my TOC initially looks like:

       

      Section 1

      item one.... X - 1

      item two.... X - 2, etc. I then highlight a range and find/change for each range.

       

      So, the script would do the following:

       

      Look in selected text (the entire TOC) frame which at times spans two or three pages from Section 1 to Section 2:

      Change the "^t (tab before number) to "^t (section number)(space)(hyphen)(space)":

      And then look at next number (i.e "4") and change the previous end of previous line from "1" to "1-3"

       

      Then repeat for range from Section 2 to Section 3, etc.

       

      Currently, I do it manually. That is ok, but it would be great to have a script that would do this for me.

       

      Thanks in advance,

       

      RPP

        • 1. Re: newbee needs suggestions for a search and replace script
          Paeon Level 1

          The last thing you need is a script.

           

          When you want to make your TOC, go to Pages, Numbering and Section Options, and put a section prefix in like 1- for each section (both 1 and 2 in your case). Click "Include Prefix When Numbering Pages".

           

          Then make your TOC.

           

          It will have all the section prefixes. ("1-1", "2-2-4", examples)

           

          Now just change the Numbering and Section Options BACK to your pre-TOC defaults. As long as  you don't update the TOC under Layout/Update TOC, your TOC text will contain the prefix, but your page numbers will look normal. If you have to change the text in the TOC for any reason, do it manually.

           

          Let me know if that works.

           

          Greg Ledger

          www.macproductionartist.wordpress.com

          • 2. Re: newbee needs suggestions for a search and replace script
            rpollack-2 Level 1

            Thank you for your suggestion. At least one person responded.

             

            However, this is will not work for our situation.

             

            I have an alternate method, but it is not the best. The suggestion you present means altering documents that already approved. I would either have to work from duplicate documents or recheck each document in the book after the TOC is done. Either way, I still have to do a search and replace (which is working for us, but I'd like to script that step).

             

            I'll let you know more soon.

             

            RPP

            • 3. Re: newbee needs suggestions for a search and replace script
              Paeon Level 1

              Sounds like you need a GREP find and replace solution. I only use it on basic level to style my docs. O'Reilly has a guide to ID and GREP. Hope you are technical. If you could set up your toc to have different stylenames for each section, then you'd just search for a string like "/d+|/d+-/d+" (one or more digits OR one or more digits hyphen one or more digits (example: 22 or 23-25) whose paragraph style is "that paragraph style", replace with "1-$0" , which should give you 1-22, or 1-23-25.

               

              I'm a newbie at GREP, so if this is the way you want to go, you should repost this question as a GREP question.

               

              That's the best I can do. Good luck.

              • 4. Re: newbee needs suggestions for a search and replace script
                rpollack-2 Level 1

                Thanks again for your reply.

                 

                As I mentioned, I have an alternative method which is not the most desirable (which you touch on in your last reply "different stylenames for each section"). However that has other inherent challanges.

                 

                Our programmer here at work has just provided me with the script I need. I am test it now, but it appears to work great. I may post it here in the future if he has no objections.

                 

                Thanks again.

                 

                RPP

                • 5. Re: newbee needs suggestions for a search and replace script
                  Paeon Level 1

                  You have a programmer? How lucky is that. My company is run by luddites (I basically have to sneak my scripting/xml/grep solutions in off hours).

                   

                  Anyway, I'd really like it if you could share that script on this post.

                   

                  Once again, good luck.

                   

                  Greg

                  • 6. Re: newbee needs suggestions for a search and replace script
                    rpollack-2 Level 1

                    Thanks again for your reply.

                     

                    He's not "my" programmer. He works at our company and is very, very smart. (I think he belongs to his spose:)).

                     

                    I am trying to learn scripting. I have included some basic GREP in our styles and they word well.

                     

                    Anyway. I am testing the script now, and when I am sure it does not error out, I will post for other. I hope to submit a tutorial on how we do our TOC in the near future.

                     

                    Regards,

                     

                    RPP