2 Replies Latest reply on Feb 26, 2008 4:33 AM by [Jongware]

    Need help !!! Multiple Find and Replace at one Click

      Hello Experts,

      I'm very basic in scripting. Not done any script
      languages before. I'm trying to learn indesign scripting and
      I need help in developing on script tool. Many
      files I work for client, regularly I have to
      check for all extra spaces, like double spaces
      after period, extra paragraph returns, space
      before and after slashes and many things like
      that. For that I want to create a script which
      by clicking will find and replace all those
      extra spaces I want to remove. I found some
      properties but no idea how to start the function use the properties.
      Can you please give the code how to start and include them?
      {findText:" "} {changeText:" "}
      {findText:". "} {changeText:". "}
      {findText:" / "} {changeText:"/"}
      {findText:"/ "} {changeText:"/"}
      {findText:" /"} {changeText:"/"}
      {findText:"--"} {changeText:""}
      {findText:"^p^p"} {changeText:"^p"}
      {findText:"^p "} {changeText:"^p"}
      {findText:" ^p"} {changeText:"^p"}

      One thing we have in Indesign ,Resources, extras in CD,
      Text cleanup tool but it is always asking for
      the source file. Instead of doing that, I want
      that script inside script panel to click and get
      done what I want.

      Can you please give me the code so that when I finished my work I can just click and it will be done instead of asking/selecting a external code file?

      If it is already explained, please give me the link.
      Oh..I forgot to tell that I'm working in CS2 and
      using Windows.

      Highly appreciation and Many many thanks in advance for the help.

      Prasant
        • 1. Re: Need help !!! Multiple Find and Replace at one Click
          Level 1
          Hello Experts,

          I'm very basic in scripting. Not done any script
          languages before. I'm trying to learn indesign scripting and
          I need help in developing on script tool. Many
          files I work for client, regularly I have to
          check for all extra spaces, like double spaces
          after period, extra paragraph returns, space
          before and after slashes and many things like
          that. For that I want to create a script which
          by clicking will find and replace all those
          extra spaces I want to remove. I found some
          properties but no idea how to start the function use the properties.
          Can you please give the code how to start and include them?
          {findText:" "} {changeText:" "}
          {findText:". "} {changeText:". "}
          {findText:" / "} {changeText:"/"}
          {findText:"/ "} {changeText:"/"}
          {findText:" /"} {changeText:"/"}
          {findText:"--"} {changeText:""}
          {findText:"^p^p"} {changeText:"^p"}
          {findText:"^p "} {changeText:"^p"}
          {findText:" ^p"} {changeText:"^p"}

          One thing we have in Indesign ,Resources, extras in CD,
          Text cleanup tool but it is always asking for
          the source file. Instead of doing that, I want
          that script inside script panel to click and get
          done what I want.

          Can you please give me the code so that when I finished my work I can just click and it will be done instead of asking/selecting a external code file?

          If it is already explained, please give me the link.
          Oh..I forgot to tell that I'm working in CS2 and
          using Windows.

          Highly appreciation and Many many thanks in advance for the help.

          Prasant
          • 2. Re: Need help !!! Multiple Find and Replace at one Click
            [Jongware] Most Valuable Participant
            The text cleanup sample script is actually a very advanced piece of javascript, using an external data file and such.

            To begin with, it's easier to just write all of the search-and-replace lines in a single file where you can add and remove individual replaces at will.

            Start with this:

            // Ensure clear settings in the find/change box
            app.findPreferences = null;
            app.changePreferences = null;

            // This is the magic line to repeat
            app.activeDocument.search ("/ ",false,true,"/");

            The 'search' method actually does the Search AND Replace at once; the first text is the one to search for, the last one its replacement. Check the JS manual for the other 2 arguments -- I'm in CS3 now and the syntax has changed.

            You can repeat this line as much as you want with different s&r texts. Searching for
            i text attributes
            also use the find/changePreferences -- you can also find this in the manual.