3 Replies Latest reply on Jun 11, 2010 8:26 AM by Tom Usrey

    Apply new settings (from Justification panel) to all text of existing doc - CS3 ?

    Tom Usrey Level 3

      I'm just getting starting with Javascript and am having trouble figuring this out. (At my age, learning scripting is the equivalent of learning Russian so I just so I can order "huevos rancheros". It's a real struggle.)

       

      With a CS3 document open, I need a script to apply my settings for all the values in the Justification panel (word spacing, letter spacing, etc.). The script below shows me how to find a certain font and apply the values, but how do I apply my values to all the type in the document?

       

      app.findTextPreferences = null;
      app.findTextPreferences.appliedFont = "Times New Roman\tItalic";

       

      foundItems = app.activeDocument.findText();
      for (i=0; i<foundItems.length; i++)
      {
      foundItems[i].minimumWordSpacing = 70;
      foundItems[i].desiredWordSpacing = 90;
      foundItems[i].maximumWordSpacing = 110;
      }

        • 1. Re: Apply new settings (from Justification panel) to all text of existing doc - CS3 ?
          [Jongware] Most Valuable Participant

          Well, you are halfway there!

           

          You are correct: your sample "finds" everything with Times New Roman applied, then changes the stuff it has found. That's because the findText routine returns an array of 'Text' (in the InDesign sense; it comes with formatting and all).

           

          The common object you were looking for is "Story" -- each and every text in your entire document has its own Story.

           

          foundItems = app.activeDocument.stories;
          for (i=0; i<foundItems.length; i++)
          {
          foundItems[i].minimumWordSpacing = 70;
          foundItems[i].desiredWordSpacing = 90;
          foundItems[i].maximumWordSpacing = 110;
          }
          • 2. Re: Apply new settings (from Justification panel) to all text of existing doc - CS3 ?
            [Jongware] Most Valuable Participant

            Ahh -- I was just typing in a long story but was rudely interrupted by a client :-P

             

            The story was about ... Stories! Since you want to change *every* text -- and that's equal to every *story* -- you can use a handy shortcut. "Stories" is a proper InDesign collection, which is a sort of array, but supports a few more properties than your own common variety (such as the ones you make yourself, and I think the ones returned by findGrep and simply using app.activeDocument.stories[x] as well).

             

            Other scripters are more into the zone on this subject, and are invited to freely comment on my layman's explanation ...

             

            In short, it means several important objects come with functions like "firstItem", "previousItem", "nextItem", and, yes! "everyItem". I always have to try before I know this will work under certain circumstances. Lo and behold: for your purposes, this appears to work just fine:

             

            app.activeDocument.stories.everyItem().minimumWordSpacing = 70;
            app.activeDocument.stories.everyItem().desiredWordSpacing = 90;
            app.activeDocument.stories.everyItem().maximumWordSpacing = 110;

            • 3. Re: Apply new settings (from Justification panel) to all text of existing doc - CS3 ?
              Tom Usrey Level 3

              Many thanks for taking the time to answer my post. I tried both your scripts and both do exactly what we needed. If you're ever in Dallas, I owe you some "huevos rancheros" and a margarita.