Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

GREP to convert first letter of all paragraphs from lowercase to uppercase?

Guru ,
Jan 18, 2017 Jan 18, 2017

Please don't ask how I inherited this text, but I have a book where every paragraph starts with a lowercase letter.

I was able to convert all of the lowercase letters to uppercase by running ^a to A, then ^b to B, ^c to C, etc. It only took 26 times.

But would there have been a more succinct way to do it in one fell swoop?

TOPICS
Scripting
4.3K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Jan 18, 2017 Jan 18, 2017
LEGEND ,
Jan 18, 2017 Jan 18, 2017
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Jan 18, 2017 Jan 18, 2017

You sir, are a genius!!!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 18, 2017 Jan 18, 2017

… Simply a Jedi! 

(^/)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 18, 2017 Jan 18, 2017

Hi!

I was struggling with similar problem couple of weeks ago.

I like you approach, but from my point of view it has one gap - it does not handle paragraph styles or character styles placed in groups.

To deal with it I came with something like this:

var myDoc = app.activeDocument;

// array of paragraph styles names to populate ddl

// it uses allParagraphStyles to get every paragraph style, regardles of the group

var myParagraphStyles = [];

for(i=0; i < myDoc.allParagraphStyles.length; i++){

        myParagraphStyles.push(myDoc.allParagraphStyles.name);

};

// remove [no paragraph] from array

myParagraphStyles.shift();

// dialog window with ddl of documents paragraph styles

var w = new Window('dialog', 'chose style');

var ddlApplyStyle = w.add('dropdownlist', undefined, myParagraphStyles);

w.add ('button', undefined, 'apply', {name: 'ok'});

w.add ('button', undefined, 'cancel', {name: 'cancel'});

   

// apply style or exit

if(w.show() == 1){

    applyStyle();

};

else{

    exit();

};

function applyStyle(){

    // name of chosen style transformed by function into real paragraph style object

    var pickedStyle = getStyleFromDDL(ddlApplyStyle.selection.text);

    // reference to text we want to change

    var myText = myDoc.stories[0];

    /// applying desired paragraph style

    myText.appliedParagraphStyle = pickedStyle;

}

// function takes ddl selection and returns paragraph style object

function getStyleFromDDL(myDDLtext){

    // check if style selected in ddl is outside of any group and create variable with paragraph style object

    if (myDoc.paragraphStyles.item(myDDLtext) != null && myDoc.paragraphStyles.item(myDDLtext).parent.constructor.name == 'Document') {

       var styleToApply = myDoc.paragraphStyles.item(myDDLtext);

    };

    // or create reference with parent group

    else{

        var myGroups = myDoc.paragraphStyleGroups;

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

            for (var j = 0; j < myGroups.paragraphStyles.length; j++) {

                if (myGroups.paragraphStyles.name == myDDLtext) {

                    var styleToApply = myGroups.paragraphStyles.item(myDDLtext);

                };

            };

        };

    };

    return styleToApply;

};

What do you think about this?

..

Jarek

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Jan 18, 2017 Jan 18, 2017

Your going to have to have this discussion with Monsieur Obi Wan Kenobi as I am hardly the script person he is.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 30, 2018 Jan 30, 2018

foltman, combination script of Obi Wan Kenobi and your is solution of my problem (i have styles in group), but im no programmer. Can you combine this scripts? it certainly will not only help me.

Thanks

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 09, 2020 Jan 09, 2020

Can you send the link of Change Case

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 10, 2020 Jan 10, 2020
LATEST

Hi together,

I hope Foltman is looking into this thread again.

His script code was damaged by moving this thread to the new forum.

 

Example: The iterator i is missing inside the for-loop:

for(i=0; i < myDoc.allParagraphStyles.length; i++){
	myParagraphStyles.push(myDoc.allParagraphStyles.name);
};

 

The corrected code for this part is this:

for(i=0; i < myDoc.allParagraphStyles.length; i++){
	myParagraphStyles.push(myDoc.allParagraphStyles[i].name);
};

 

Other corrections should be made as well. Only Foltman could edit this old post from 2017, I think.

 

Regards,
Uwe Laubender

( ACP )

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines