ChangeCase [JS]

I have this piece of code

find = app.documents [0] .findGrep ();
for (i = 0; i < finds.length; i ++) {}
finds [i] .silence = finds [i].contents.toLowerCase (); }

That works very well for the lowercase and uppercase

Can someone tell me how to get TitleCase or sentence case to work please...

Use the InDesign changecase options:

discoveries [i] .changecase (ChangecaseMode.titlecase);

Peter

Tags: InDesign

Similar Questions

  • Make a case to sentence the words?

    Hi I'm doing a script to change all the major changes we make in a document.  I'm sure that grep will take care of this, but again, I am trying to combine about 6 different functions in a script.  How would I go about changing the 2 lines of text in the event of conviction? The top line should be changed and the 2 bottom would need has changed because of the sentence.  Is it possible to add this grep string in my script?

    Works by case title here "it is the only line that can be left alond.

    The case of the sentence works changed here needs

    The case of the sentence works changed here needs

    useful for you below:

    Re: ChangeCase [JS]

    Re: find letters - change down

    How to insert a signal to find out (all?) script is run?

    How to modify this script, increase a case that is "change to each letter of the word'first capital.

  • Fixing of capitalization of the index

    I'm creating an index by working through the document, pointing out the words or phrases I want, press option 7 (CS4 on Mac). However, many of the words begin with a capital letter in the text while I'm envy them all lowercase in the index. I can fix it at registration. However, is there a way I could, once the index is finalized and I do not need to be updated more, change them to all lowercase letters as a batch?  At that point, they will be just like another block of text.

    Hi Mary,

    If the first character in the origin of each paragraph in the story, which contains the text of the index, start with lowercase letters?

    Then you can use an ExtendScript (JavaScript) to set the first character at the beginning of each paragraph of the selected lowercase text.

    Select all of the text, which should be assigned, and run the following script:

    app.selection[0].paragraphs.everyItem().characters[0].changecase(ChangecaseMode.LOWERCASE);
    

    For usage, mounting and installation of ExtendScript scripts scroll down page of Peter Kahrel:

    InDesign: Index of character styles. Peter Kahrel

    Regrads,
    Uwe

  • Change the case on several documents

    Hello!

    I'm very new to scripting, and I have the following script that is "Upper" text and change for real uppercase. I work with ID CS 6 on Windows XP.

    The script works on a single document, if there is an open, if not, it asks for a file and process all INDD files in this folder.

    That's what I have:

    if(app.documents.length != 0){
        processDocument(app.activeDocument);
        alert("Done!");
        }
    else {
        _folder = Folder('~/Desktop').selectDlg("Select folder");
        if(_folder == null) exit();
        _files = _folder.getFiles("*.indd");
        if(_files.length == 0){
                alert("No INDD files in the selected folder!");            
            }
        else {
            for (i=0; i<_files.length; i++){
            app.scriptPreferences.userInteractionLevel = UserInteractionLevels.NEVER_INTERACT;
            _inddFile = _files[i]
            doc = app.open(_inddFile);
            app.scriptPreferences.userInteractionLevel = UserInteractionLevels.INTERACT_WITH_ALL;      
            processDocument(doc);
            app.activeDocument.close(SaveOptions.yes);
            } 
        alert("Done!");
        }
    }
    
    function processDocument(doc) {    
        app.findGrepPreferences = app.changeGrepPreferences = null;
        app.findGrepPreferences.capitalization = Capitalization.allCaps;
        app.findGrepPreferences.appliedCharacterStyle = 'Red';
        var _results = doc.findGrep();
        app.findGrepPreferences = app.changeGrepPreferences = null;    
        _length = _results.length;
        for (i=0; i<_length; i++) {
            _results[i].texts[0].changecase(ChangecaseMode.uppercase);
            _results[i].texts[0].capitalization = Capitalization.normal;
            _results[i].texts[0].appliedCharacterStyle = 'Blue';
        }
    }
    

    The script works well on a single document, but for some reason any that it does not work on several documents. I try the script on 4 files with this content (the colors are added in the text only to help verify the results):

    Whenever the first or the first two documents are processed correctly, the others are not processed at all. But I get no error message. Where is the problem?

    Any help would be greatly appreciated!

    Luca

    I tried to recreate your problem once again and I don't have something similar. I know it's not normal, but mine started when I changed the variable i in the second. I see that they have a different scope, but somehow she made the difference. Could you try it by chance?

    #target indesign
    if(app.documents.length != 0){
        processDocument();
        alert("Done!");
        }
    else {
        _folder = Folder('~/Desktop').selectDlg("Select folder");
        if(_folder == null) exit();
        _files = _folder.getFiles("*.indd");
        if(_files.length == 0){
                alert("No INDD files in the selected folder!");
            }
        else {
            for (i=0; i<_files.length; i++){
            app.scriptPreferences.userInteractionLevel = UserInteractionLevels.NEVER_INTERACT;
            _inddFile = _files[i] ;
            doc = app.open(_inddFile);
            app.scriptPreferences.userInteractionLevel = UserInteractionLevels.INTERACT_WITH_ALL;
            processDocument(doc);
            app.activeDocument.close(SaveOptions.yes);
            }
        alert("Done!");
        }
    } 
    
    function processDocument() {
        app.findGrepPreferences = app.changeGrepPreferences = null;
        app.findGrepPreferences.capitalization = Capitalization.allCaps;
        app.findGrepPreferences.appliedCharacterStyle = "Red";
        var _results = app.activeDocument.findGrep();
        $.write(_results);
        app.findGrepPreferences = app.changeGrepPreferences = null;
        _length = _results.length;
        $.write(_length);
        for (s=0; s<_length; s++) {
            _results[s].texts[0].changecase(ChangecaseMode.uppercase);
            _results[s].texts[0].capitalization = Capitalization.normal;
            _results[s].texts[0].appliedCharacterStyle = 'Blue';
        }
    }
    
  • java file on the server call

    Hello. I created the file directory on my server and the java file loaded through Resource Directory Oracle to the developer. How can I call and run this file through SQL developer and use someday in the Apex. Thank you.

    Sorry, I forgot to mention the PL/SQL Wrapper. Here's the complete code:

    SQL> create or replace and compile
      2  java source named "HelloWorld"
      3  as
      4  public class HelloWorld {
      5     public static String changeCase(String inputValue){
      6             return inputValue.toUpperCase();
      7     }
      8  }
      9  /
    
    Java created.
    
    SQL> create or replace function changecase(p_inp varchar2) return varchar2
      2  as language java
      3  name 'HelloWorld.changeCase(java.lang.String) return java.lang.String';
      4  /
    
    Function created.
    
    SQL> select changecase('abc') chcase from dual;
    
    CHCASE
    --------------------------------------------------------------------------------
    ABC
    
  • Why this unfunction script?

    Hello world

    can you find the wrong syntax for this script and help me to fix it?


    app.findGrepPreferences = app.changeGrepPreferences = null;
    var doc = app.activeDocument,
    _selection = app.selection [0] .words;

    var ignoreWords = "one, a, and, the, to, with, in, on, title or, to, in, by, their, then, for, are, which is, be"


    app.findGrepPreferences.appliedParagraphStyle = '01 H1;

    find = app.selection [0] .findGrep ();

    for (var i = 0; i < finds.length; i ++) {}

    If (ignoreWords.IndexOf (_selection [i]. (Happy) == - 1).
    {
    finds [i] .texts [0]. ChangeCase (ChangecaseMode.titlecase);
    }
    }

    app.findGrepPreferences = app.changeGrepPreferences = null;

    John

    Hi John,.

    ".name" should be added at line 8 with appliedParagraphStyle. Change line 8 Jarek script as below.

    if(_selection[i].appliedParagraphStyle.name == "01 H1" && ignoreWords.indexOf(_selection[i].contents) == -1) 
    

    Kind regards

    Cognet

  • find uppercase - change down

    Hi all

    I have a bibliography that contains many names in uppercase.

    Is there a script or grep to find all of these words and change them alive in lower case only the first letter capitalized?

    for example: MARK TWAIN > Marc Twain; G. ORSON WELLES > g. Orson Welles

    I can find uppercase with grep "\u+" but I can't change them in lowercase.

    Thanks in advance

    Try this,

    app.findGrepPreferences = app.changeGrepPreferences = null;

    app.findGrepPreferences.findWhat = "\\u+";

    find = app.selection [0] .findGrep ();

    for (var i = 0; i)<>

    finds [i] .texts [0]. ChangeCase (ChangecaseMode.titlecase);

    }

    app.findGrepPreferences = app.changeGrepPreferences = null;

  • How to insert a signal to find out (all?) script is run?

    This script works silently and without advice, but sometimes the double click is not well done.

    And the only way to check if the output is export the file, which is a waste of time.

    I would insert a line which confirms the action.

    app.findGrepPreferences = null;

    app.findGrepPreferences.findWhat = "\\l\\l+";

    app.findGrepPreferences.appliedCharacterStyle = app.activeDocument.characterStyles.item ("XX");

    foundList = app.activeDocument.findGrep (true);

    for (i = 0; i < foundList.length; i ++)

    foundList [i] .changecase (ChangecaseMode.UPPERCASE);

    Thank you:

    Hi Camilo,

    At the end of the script, add this line:

    alert ('Done!');
    

    or, if you're desperate to know how many times the character style has been applied,

    alert ('Found ' + i + ' acronyms.');
    

    Peter

  • higher to lower the selected text

    Change the THIRD character lowercase

    Peter Kahrel wrote the original of the present.

    app.findGrepPreferences = app.changeGrepPreferences = null;

    app.findGrepPreferences.appliedParagraphStyle = "list";

    Third paragraph lowercase letter:

    app.findGrepPreferences.findWhat = "^.» {3}";

    found = app.activeDocument.findGrep ();

    for (i = 0; i < found.length; i ++)

    found [i] .characters [2] .changecase (ChangecaseMode.lowercase);

    The script above (modified by Peter) works very well (ID CC), but would it be possible to make it work on a selected instead of level paragraph text? because we can always change the name of style (new paragraph because of export txt to other applications).

    To be clear: select text and run the script for the selection.

    Hello

    Look at the two lines:

    app.findGrepPreferences.appliedParagraphStyle = "list";

    Comment this line to turn off the status of .appliedParagraphStyle

    found = app.activeDocument.findGrep ();

    change the red part of the line to set another target for the findGrep() method, that is:

    found = app.selection [0] .findGrep () / / if the text selected

    or

    found = app.selection [0].parentStory.findGrep () / / if textFrame selected

    Jarek

  • uppercase to lowercase in the list 'false. '

    http://InDesignSecrets.com/convert-text-to-lowercase-with-grep-utility.php

    Is a thread that I found. It converts the first char in a paragraph style "list bullet" in lowercase.
    Works very well, but often we have lists for that, for several reasons, we cannot use the automatic feature 'list' (copy paste issues with other programs, etc.). The first tank is the - (alt + 0151) followed by a space (no tab) or • tank (alt + 0149).
    I can't understand it with grep function, because there is no mention of the possibility of "tiny".
    Any suggestions?

    I was able to change the script of Peter Kahrel quite easily to change the third character instead of the first, which I think would be to do what you want.

    Change the THIRD character lowercase

    Peter Kahrel wrote the original of the present.

    app.findGrepPreferences = app.changeGrepPreferences = null;

    app.findGrepPreferences.appliedParagraphStyle = "list";

    Third paragraph lowercase letter:

    app.findGrepPreferences.findWhat = "^.» {3}";

    found = app.activeDocument.findGrep ();

    for (i = 0; i< found.length;="">

    found [i] .characters [2] .changecase (ChangecaseMode.lowercase);

    I changed

    app.findGrepPreferences.findWhat = "^." TO

    app.findGrepPreferences.findWhat = "^.» {3}"; If she takes the first three characters of the paragraph instead of a single

    and

    found in [i] .characters [0] .changecase (ChangecaseMode.lowercase); TO

    found [i] .characters [2] .changecase (ChangecaseMode.lowercase); then, it changes the third character instead of the first.

    The script always depends on the text aving a named style applied (in this case I left it to the 'list') you may need to further modify to change the name of style to match your situation.

    And if you wanted, I think you could probably change app.findGrepPreferences.findWhat = "^." for app.findGrepPreferences.findWhat = "^.» + » ; to find all of the paragraph, and then change the index in the table to match any character position of your choice, but I don't think that a lot of purpose. One of the Scripting Guys could probably Jazz with an interface that asks the character you want to change.

  • Help: How to fix a line in this script (well almost) on the change of the actual text capital LETTERS?

    app.findGrepPreferences = null;

    app.findGrepPreferences.findWhat = "\\l\\l+";

    app.activeDocument.characterStyles.item ("SC");

    foundList = app.activeDocument.findGrep (true);

    for (i = 0; i < foundList.length; i ++)

    foundList [i] .changecase (ChangecaseMode.UPPERCASE);

    The idea is to choose the magenta words in salt to be set in uppercase.

    The problem is the script (based in Jongware and P. Kahrel) is to convert all the texts for no capital letters not assuming that the condition to the style of characters 'SC'.

    Instead, it evolves throughout the text:

    upper.jpg

    Try:

    app.findGrepPreferences.appliedCharacterStyle = app.activeDocument.characterStyles.item ("SC");

    * not tested

  • Need a stop block in my script

    Hi Forum,

    I have been very useful to learn the vamitul and Jarek previous thread helps...

    but still I'm late here and my mind blocked...

    my script now to the content of the previous paragraph to find last character ': "if so, it will change all the paragraphs of balls first letter to ceilings...

    It is what happens, convert all letters to paragraph ball caps...

    So now the stop block is necessary to check, & stop change first bullet uppercase letter if the previous paragraphs end character is not equal to ":

    var oDoc = app.activeDocument;

    arr = [];

    var myNextPara = oDoc.textFrames.everyItem () .getElements ();

    for (k = 0; k < myNextPara.length; k ++) {}

    myReturn = myNextPara [k].parentStory.paragraphs.firstItem (myNextPara [k] .paragraphs [0])

    {if (myReturn.IsValid)}

    If (myReturn.bulletsAndNumberingListType! == ListType.BULLET_LIST & &)

    myReturn.lines.lastItem (). words.lastItem (). characters.lastItem (.silence) == ":" & & "."

    myReturn.paragraphs.nextItem(myNextPara[k].paragraphs[0]).bulletsAndNumberingListType == ListType.BULLET_LIST)

    {

    changeCase();

    }

    If {myReturn.lines.lastItem (). words.lastItem (). characters.lastItem (.silence)! == ': ') {}

    output

    } } }

    function changeCase() {}

    app.findGrepPreferences.bulletsAndNumberingListType = ListType.BULLET_LIST;

    app.findGrepPreferences.findWhat = "^ (\\l);

    find = app.documents [0] .findGrep ();

    for (i = 0; i < finds.length; i ++) {}

    finds [i] = [i] finds .silence .silence [0] .toUpperCase ();

    }}

    Screen Shot 2013-08-22 at 14.14.44.png

    Hello

    so, lets include a paraStepper() function:

    app.findGrepPreferences = app.changeGrepPreferences = null;
    app.findGrepPreferences.findWhat = ":\\s*\r.";     // to match 2 paras - end & start
    
    var myDoc = app.activeDocument,
    mFound = myDoc.findGrep(),
    len = mFound.length, currPara;
    
    while (len--) {
         currPara = mFound[len].paragraphs[0];
         if (currPara.bulletsAndNumberingListType != ListType.BULLET_LIST){
                        currPara = paraStepper(currPara);
                        while (currPara) {
                                  currPara.words[0].characters[0].changecase(ChangecaseMode.UPPERCASE);
                                  currPara = paraStepper(currPara);
                                  }
                        }
         }
     function paraStepper (para){
               var mRes = false,
               story = para.parentStory,
               next = story.paragraphs.nextItem(para);
               if (next.isValid && next.bulletsAndNumberingListType == ListType.BULLET_LIST)
                        mRes = next;
              return mRes;
               }
    app.findGrepPreferences = app.changeGrepPreferences = null;
    

    Jarek

  • Dave Saunders update find the script style/change case

    How can I update a script of Dave Saunders of CS1 and CS2 to CS5?

    He wrote a brilliant script that looks for a paragraph style and becomes the upper case or lower.

    However, it was for CS1 and CS2.   I can't make it work on CS5.

    it triggers in

    app.findPreferences = null;
    object does not support the "findPreferences".

    Here's the script.  Thanks for your help!

    DESCRIPTION: Converts the text referred to the designated case parastyle

    If ((app.documents.length! = 0) & & (app.selection.length! = 0)) {}
    myDoc = app.activeDocument;
    myStyles = myDoc.paragraphStyles;
    myStringList = myStyles.everyItem () .name;
    myCaseList = ["uppercase","tiny", "Title case", "Sentence case"];
    myCases = [ChangecaseMode.uppercase, ChangecaseMode.lowercase, ChangecaseMode.titlecase, ChangecaseMode.sentencecase];

    myDialog = app.dialogs.add var ({name: 'Case changer'})
    {with (MyDialog)}
    {with (dialogColumns.Add ())}
    with (dialogRows.add ()) {}
    with (dialogColumns.add ()) {}
    staticTexts.add ({staticLabel: "Style of paragraph :"});})
    }
    with (dialogColumns.add ()) {}
    myStyle = dropdowns.add({stringList:myStringList,selectedIndex:0,minWidth:133});)
    }
    }
    with (dialogRows.add ()) {}
    with (dialogColumns.add ()) {}
    staticTexts.add ({staticLabel: "change case to :"}); "})
    }
    with (dialogColumns.add ()) {}
    myCase = dropdowns.add({stringList:myCaseList,selectedIndex:0,minWidth:133});)
    }
    }
    }
    }
    Ditto var = myDialog.show ();
    If (ditto! = true) {}
    the user has clicked Cancel
    myDialog.destroy ();
    errorExit();
    }
    theStyle = myStyle.selectedIndex;
    Case = myCase.selectedIndex;
    myDialog.destroy ();

    app.findPreferences = null;
    app.changePreferences = null;
    myFinds = myDoc.search (', false, false, undefined, {appliedParagraphStyle:myStyles[theStyle]});})
    myLim = myFinds.length;
    for (var j = 0; myLim > j; j ++) {}
    myFinds [j] .texts [0] .changecase (myCases [theCase]);
    }

    } else {}
    errorExit();
    }

    +++ Functions start here +++

    function errorExit (message) {}
    If (arguments.length > 0) {}
    If (app.version! = 3) {beep()} / / CS2 includes beep() function.
    Alert (message);
    }
    Exit(); CS ends with a beep; CS2 left silently.
    }

    I had wanted this script to work for centuries, as well, but I started studying javascript in InDesign several weeks reading Scripting InDesign CS3/4 with Javascript by Peter Kahrel. Even though it says CS3/4, he won't be in CS5. Not sure if Peter put updated recently or not.

    In any case, thanks to that and Haakenlid and Manan help, I was able to update the script and make it work successfully. I the extent of change "app.findPreferences = null;" to "app.findTextPreferencess = NothingEnum.NOTHING;", but I was stuck on line 43 (myFinds = myDoc.search...). I had to change something in the code of Haakenlid: "appliedParagraphStyle" should be "appliedCharacterStyle". Without further ADO, here's the script fixed:

    DESCRIPTION: update the script of ChangeCaseOfSelectedStyle of Dave Saunder for CS5 and later

    If ((app.documents.length! = 0) & (app.selection.length! = 0)) {}

    myDoc = app.activeDocument;

    myStyles = myDoc.characterStyles;

    myStringList = myStyles.everyItem () .name;

    myCaseList = ["uppercase","tiny", "Title case", "Sentence case"];

    myCases = [ChangecaseMode.uppercase, ChangecaseMode.lowercase, ChangecaseMode.titlecase, ChangecaseMode.sentencecase];

    myDialog = app.dialogs.add var ({name: 'Case changer'})

    {with (MyDialog)}

    {with (dialogColumns.Add ())}

    with (dialogRows.add ()) {}

    with (dialogColumns.add ()) {}

    staticTexts.add ({staticLabel: "Style of character :"});})

    }

    with (dialogColumns.add ()) {}

    myStyle = dropdowns.add({stringList:myStringList,selectedIndex:0,minWidth:133});)

    }

    }

    with (dialogRows.add ()) {}

    with (dialogColumns.add ()) {}

    staticTexts.add ({staticLabel: "change case to :"}); "})

    }

    with (dialogColumns.add ()) {}

    myCase = dropdowns.add({stringList:myCaseList,selectedIndex:0,minWidth:133});)

    }

    }

    }

    }

    Ditto var = myDialog.show ();

    If (ditto! = true) {}

    the user has clicked Cancel

    myDialog.destroy ();

    errorExit();

    }

    theStyle = myStyle.selectedIndex;

    Case = myCase.selectedIndex;

    myDialog.destroy ();

    app.findTextPreferences = NothingEnum.NOTHING;

    app.changeTextPreferences = NothingEnum.NOTHING;

    app.findTextPreferences.appliedCharacterStyle = myStyles [theStyle]; var myFinds = myDoc.findText ();

    myLim = myFinds.length;

    for (var j = 0; myLim > j; j ++) {}

    myFinds [j] .texts [0] .changecase (myCases [theCase]);

    }

    } else {}

    errorExit();

    }

    +++ Functions start here +++

    function errorExit (message) {}

    If (arguments.length > 0) {}

    If (app.version! = 3) {beep()}

    Alert (message);

    }

    Exit();

    }

  • Cleanup script

    Hi all

    Often, we translate indesign files using a cat tool to open the idml file. But most of the InDesign files that are sent to us was created by people who take a great many short cuts to get things to fit, that might be good for them but not for us.

    We need a script that affect all kerning 0 or a constant value throughout a document, delete all text stretched and change something with true uppercase all THE CORKS.

    There is a little more things to do to clean it upward which can take a few hours for a large document so it would be good that he had a script that could do or if anyone knows how to create one for us, we would be happy to work with you to create.

    Here is a new version:

    const kerningConstant = 0;
    var doc = app.activeDocument,
    stories = doc.stories,
    story, text, s, t;
    
    for (var s = 0; s < stories.length; s++) {
         story = stories[s];
         for (var t = 0; t < story.texts.length; t++) {
              text = story.texts[t];
              text.kerningValue = kerningConstant;
              text.verticalScale = 100;
              text.horizontalScale = 100;
              ChangeCase(text);
         }
    }
    
    function ChangeCase(text) {
         var i, found;
         if (text.contents != "") {
              app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.nothing;
              app.findGrepPreferences.findWhat = ".+";
              app.findGrepPreferences.capitalization = Capitalization.ALL_CAPS;
              var found = text.findGrep();
              if (found.length > 1) {
                   for (i = 0; i < found.length; i++) {
                        // $.writeln( i + " - " + found[i].constructor.name + "/"+ found[i].contents );
                        found[i].changecase(ChangecaseMode.UPPERCASE);
                   }
                   app.changeGrepPreferences.capitalization = Capitalization.NORMAL;
                   text.changeGrep();
              }
         }
    }
    

Maybe you are looking for