7 Replies Latest reply on Mar 31, 2009 6:47 AM by (Robert_Tkaczyk)

    Headline caps change for a newspaper

    masc145
      How can change the first letter to an uppercase of a word in headline (paragraph), except for words of 1,2 and 3 letter words, with a script?
        • 1. Re: Headline caps change for a newspaper
          [Jongware] Most Valuable Participant
          With the changecase function. JS can access individual words in paragraphs, in the following way<br /><br /><pre>for (i=0; i<app.activeDocument.selection[0].paragraphs[0].words.length; i++)<br /><br />     if (app.activeDocument.selection[0].paragraphs[0].words[i].length > 3)<br /><br />          app.activeDocument.selection[0].paragraphs[0].words[i].changecase(ChangecaseM ode.TITLECASE);</pre>It is restricted to what InDesign counts as 'words' -- a combined word with a hyphen, "two-fold" for example, is taken as <br />i two <br />words. Applying your three-letter word rule would yield a headline such as "The Dangers of sun Rays are two-Fold". So some careful post-editing is required.
          • 2. Re: Headline caps change for a newspaper
            Level 1
            why not using NestedStyles ?

            robin

            --
            www.adobescripts.com
            • 3. Re: Headline caps change for a newspaper
              [Jongware] Most Valuable Participant
              Because I have no idea how to do that using nested styles :-)

              Besides ... even if you can make it work, doesn't that apply the character style to
              i every
              word? Nested styles cannot count the number of characters per word.
              • 4. Re: Headline caps change for a newspaper
                Level 1
                sorry :) I mean - why not to apply new ParaStyle with NestedStyle or CharaterStyle (to only first character) - instead of local formatting

                robin

                --
                www.adobescripts.com
                • 5. Re: Headline caps change for a newspaper
                  Peter Kahrel Adobe Community Professional & MVP
                  You can use a GREP style: create a character style that sets All Caps, then let the GREP expression \b\l(?=\w\w\w) apply that character style to the first lower-case letter of words of four or more characters long.

                  Peter
                  • 6. Re: Headline caps change for a newspaper
                    [Jongware] Most Valuable Participant
                    I first tried to mess with JavaScript cased changing -- using the built-in string function toUppercase. Then I remembered ID has a user interface function for title case, and wondered if it was the same in JS. And yes, it was -- Uppercase, Title Case, Sentence Case and Lowercase, appliable to Text, Paragraph, Characters (which is what you'd need) ... and Word. So I don't even have to extract individual characters.
                    There are no built-in fuctions to automatically add a character style to the first character of certain words.

                    If the requirements ever change -- adding color, or a font or something to the first character --, then you'd have to work around and add stuff 'manually'. I guess that's what you have in mind.
                    • 7. Re: Headline caps change for a newspaper
                      Level 1
                      ok - I misreaded Miguel's post - and your script - NestedStyle will not work :(

                      but applying CharStyle instead of local formatting ... shouldn't be so bad idea ;)

                      robin

                      --
                      www.adobescripts.com