Professional Web Applications Themes

Changing Sentence Case in a Paragraph Style? - Adobe Indesign Windows

Is there a way to set up a "Paragraph Style" to "Change Case"? I need to change from all caps to "Title Case". Thanks for your help!...

Sponsored Links
  1. #1

    Default Changing Sentence Case in a Paragraph Style?

    Is there a way to set up a "Paragraph Style" to "Change Case"? I need to change from all caps to "Title Case". Thanks for your help!
    Sponsored Links
    Steve_Voltmer@adobeforums.com Guest

  2. #2

    Default Re: Changing Sentence Case in a Paragraph Style?

    No. Title Case actually changes the characters in the text stream, and so it is not available via styles.

    Dave
    Dave_Saunders@adobeforums.com Guest

  3. #3

    Default Re: Changing Sentence Case in a Paragraph Style?

    Besides, title case is the only command I don't use. It capitalizes
    every word even "is" and "the."

    Bob
    Bob Guest

  4. #4

    Default Re: Changing Sentence Case in a Paragraph Style?

    Bob,

    Here's a gift that should help. I call it SmartTitleCase:

    //DESCRIPTION Converts selected text to title case smartly

    //Smartly means that articles, etc. are ignored
    //and internal capitals of recognized words are retained.

    ignoreWords = ["a","and","the","to","with","in","on","as","of","o r","at","is","from","for"];
    intCaps = ["PineRidge","InDesign","NJ","UMC"];
    try
    {
    myText = app.selection[0].texts[0].contents;
    }
    catch(e)
    {
    exit();
    }

    theWords = myText.toLowerCase().split(" ");

    //First word must have a cap, but might have an internal cap

    myNewText = "";

    for (var j = 0; theWords.length > j; j++) {
    k = isIn(intCaps,theWords[j])
    if (k > -1) {
    myNewText = myNewText + intCaps[k] + " ";
    continue;
    } else {
    if ((isIn(ignoreWords,theWords[j]) > -1) && (j != 0)) {
    myNewText = myNewText + theWords[j] + " ";
    } else {
    myNewText = myNewText + InitCap(theWords[j]) + " ";
    }
    }
    }

    app.selection[0].texts[0].contents = myNewText.substring(0,myNewText.length - 1);

    function isIn(aList,aWord) {
    for (var i = 0; aList.length > i; i++) {
    if (aList[i].toLowerCase() == aWord) {
    return i;
    }
    }
    return -1;
    }

    To use the script, copy and paste to a text editor and save as a plain text file with an appropriate name in the form YourName.jsx in the Scripts folder of the Presets folder of your InDesign CS2 folder (you could put it in a subfolder if you wish). Then to run the script, double-click its name in the Scripts palette.

    Dave
    Dave_Saunders@adobeforums.com Guest

  5. #5

    Default Re: Changing Sentence Case in a Paragraph Style?

    You are truly amazing.

    Thanks a million!

    Bob
    Bob Guest

  6. #6

    Default Re: Changing Sentence Case in a Paragraph Style?

    I just get the error that InitCap is not a function.
    Dominic_Hurley@adobeforums.com Guest

  7. #7

    Default Re: Changing Sentence Case in a Paragraph Style?

    That's odd. I used this script today and didn't get the error, and yet looking over what I posted I can surely see why you got it. Perhaps I didn't copy the whole script.

    Let me try again ...

    Ah, indeed, I left it off the end. Sorry about that. Here's the correct version:

    //DESCRIPTION Converts selected text to title case smartly

    //Smartly means that articles, etc. are ignored
    //and internal capitals of recognized words are retained.

    ignoreWords = ["a","and","the","to","with","in","on","as","of","o r","at","is","from","for"];
    intCaps = ["PineRidge","InDesign","NJ","UMC"];
    try
    {
    myText = app.selection[0].texts[0].contents;
    }
    catch(e)
    {
    exit();
    }

    theWords = myText.toLowerCase().split(" ");

    //First word must have a cap, but might have an internal cap

    myNewText = "";

    for (var j = 0; theWords.length > j; j++) {
    k = isIn(intCaps,theWords[j])
    if (k > -1) {
    myNewText = myNewText + intCaps[k] + " ";
    continue;
    } else {
    if ((isIn(ignoreWords,theWords[j]) > -1) && (j != 0)) {
    myNewText = myNewText + theWords[j] + " ";
    } else {
    myNewText = myNewText + InitCap(theWords[j]) + " ";
    }
    }
    }

    app.selection[0].texts[0].contents = myNewText.substring(0,myNewText.length - 1);

    function isIn(aList,aWord) {
    for (var i = 0; aList.length > i; i++) {
    if (aList[i].toLowerCase() == aWord) {
    return i;
    }
    }
    return -1;
    }

    function InitCap(aWord) {
    if (aWord.length == 1) {
    return (aWord.toUpperCase());
    }
    return (aWord.substr(0,1).toUpperCase() + aWord.substring(1,aWord.length))
    }

    To use the script, copy and paste to a text editor and save as a plain text file with an appropriate name in the form YourName.js in the Scripts folder of the Presets folder of your InDesign CS folder (you could put it in a subfolder if you wish). Then to run the script, double-click its name in the Scripts palette. For CS2, use .jsx for the extension and put the scirpt in its Scripts folder.

    Dave
    Dave_Saunders@adobeforums.com Guest

  8. #8

    Default Re: Changing Sentence Case in a Paragraph Style?



    ... Here's the correct version:




    Excellent! Your efforts in providing things like this are much appreciated.
    Roger_Meeker@adobeforums.com Guest

  9. #9

    Default Re: Changing Sentence Case in a Paragraph Style?

    Do people realize without explanation that they can affect this script's behavior by editing the contents of the two arrays at the start, one for ignored words (always lowercase in result) and one for internal (or all) caps words (always rendered as typed in the list)?

    Would it be better if these two lists were in external files that you could edit with a text editor?

    Dave
    Dave_Saunders@adobeforums.com Guest

  10. #10

    Default Re: Changing Sentence Case in a Paragraph Style?

    It would certainly be a nice feature, Dave, the way it is now is just
    fine for my use.

    Bob
    Bob Guest

  11. #11

    Default Re: Changing Sentence Case in a Paragraph Style?



    Do people realize without explanation that they can affect this script's
    behavior by editing the contents of the two arrays at the start, one for
    ignored words (always lowercase in result) and one for internal (or all)
    caps words (always rendered as typed in the list)?





    Would it be better if these two lists were in external files that you
    could edit with a text editor?




    I did realize that myself.

    I'm of the opinion that it would be best to keep everything in the one file. Perhaps with some commented code immediately before the word list reminding them to use the quotes and commas.
    Roger_Meeker@adobeforums.com Guest

  12. #12

    Default Re: Changing Sentence Case in a Paragraph Style?

    I decided that the thing to do was let the user decide. I've written a version that after priming the lists looks for two text files called ignoreWords.txt and intCaps.txt in the same folder as the script. If either is found, then its contents replace what's in the script. If they don't exist, then what's in the script is used.

    Seemed like a simple compromise.

    You can download it from: <http://pdsassoc.com/blogscripts/2005Aug/SmartTitleCase.zip>

    If you're not interested in using the text file approach, then this download won't buy you anything over the script posted above (except perhaps the opportunity to see how to script that kind of thing).

    I have realized that the script doesn't handle the case where a word like iTunes is the first in a title. But you can get around that by simply not selecting the "i".

    Dave
    Dave_Saunders@adobeforums.com Guest

  13. #13

    Default Re: Changing Sentence Case in a Paragraph Style?

    Dave,

    Does this function correctly if you use the array for the ignore words, which seems like it would be a pretty static list, and a text file for the IntCaps? I can see where that would likely need far more customization for acronyms, abbreviations of state names and the like, depending on the individual user and their habits.

    Peter
    Peter_Spier@adobeforums.com Guest

  14. #14

    Default Re: Changing Sentence Case in a Paragraph Style?

    Yes. Each file is sought out separately.

    Check it out at my new blog! <http://jsid.blogspot.com>

    Dave
    Dave_Saunders@adobeforums.com Guest

  15. #15

    Default Re: Changing Sentence Case in a Paragraph Style?

    Thanks Dave,

    And if I wasn't half-asleep I would have seen that you said that to begin with.

    Peter
    Peter_Spier@adobeforums.com Guest

Similar Threads

  1. Trouble with Next Style in a paragraph style
    By Clark in forum Adobe Indesign Windows
    Replies: 4
    Last Post: August 7th, 01:22 PM
  2. Showing the first sentence of a paragraph
    By Micheller in forum Macromedia ColdFusion
    Replies: 8
    Last Post: May 2nd, 08:34 PM
  3. paragraph style organization
    By phases@adobeforums.com in forum Adobe Indesign Windows
    Replies: 7
    Last Post: June 15th, 06:19 AM
  4. Sentence /paragraph spacing
    By pyrolabs webforumsuser@macromedia.com in forum Macromedia Dreamweaver
    Replies: 1
    Last Post: July 8th, 08:52 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139