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

Looking for a script to change Paragraph style case to AllCaps

Explorer ,
Feb 23, 2024 Feb 23, 2024

Copy link to clipboard

Copied

Hi!

 

I'm looking for code to add to a script that will change the case of a specific paragraph style to AllCaps. To be clear, not to change all instances to uppercase but to change the case inherent to the style to AllCaps. Thanks in advance for any help!

 

Thanks,

 

Eubha

TOPICS
Scripting

Views

268

Translate

Translate

Report

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

Community Expert , Feb 23, 2024 Feb 23, 2024

Hi @EubhaLiath, this is how:

var doc = app.activeDocument;
var myParaStyle = doc.paragraphStyles.itemByName('My Style');

if (myParaStyle.isValid)
    myParaStyle.capitalization = Capitalization.ALL_CAPS;

- Mark 

Votes

Translate

Translate
Community Expert ,
Feb 23, 2024 Feb 23, 2024

Copy link to clipboard

Copied

Why not make a secondary paragraph style that is set to all caps?

Mike Witherell

Votes

Translate

Translate

Report

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 ,
Feb 27, 2024 Feb 27, 2024

Copy link to clipboard

Copied

The styles are linked to export tags so they need to stay the same. Thank you though.

Votes

Translate

Translate

Report

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 ,
Feb 23, 2024 Feb 23, 2024

Copy link to clipboard

Copied

Hi @EubhaLiath, this is how:

var doc = app.activeDocument;
var myParaStyle = doc.paragraphStyles.itemByName('My Style');

if (myParaStyle.isValid)
    myParaStyle.capitalization = Capitalization.ALL_CAPS;

- Mark 

Votes

Translate

Translate

Report

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 ,
Feb 27, 2024 Feb 27, 2024

Copy link to clipboard

Copied

That's brilliant, thank you! Exactly what I needed. Only small hiccup - it doesn't work if the style is in a style folder and I'm not sure how to alter it to sort that. Any ideas?

Votes

Translate

Translate

Report

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
Engaged ,
Feb 27, 2024 Feb 27, 2024

Copy link to clipboard

Copied

Hi @EubhaLiath 

var doc = app.activeDocument;
var myParaStyle = doc.paragraphStyleGroups.item("My Group").paragraphStyles.itemByName('My Style');

if (myParaStyle.isValid)
    myParaStyle.capitalization = Capitalization.ALL_CAPS;
Thanks,
Prabu
Design smarter, faster, and bolder with InDesign scripting.

Votes

Translate

Translate

Report

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 ,
Feb 28, 2024 Feb 28, 2024

Copy link to clipboard

Copied

LATEST

Perfect!

 

Also, for the extra case, here is how I do it when I don't want to care where the ParagraphStyle is—it might be in any paragraphStyleGroup):

 

var doc = app.activeDocument;
var myParaStyle = getThing(doc.allParagraphStyles, 'name', 'My Style');

if (undefined !== myParaStyle)
    myParaStyle.capitalization = Capitalization.ALL_CAPS;

/**
 * Returns a thing with matching property.
 *  {Array|collection} things - the things to look through, eg. PageItems.
 *  {String} key - the property name, eg. 'name'.
 *  {*} value - the value to match.
 */
function getThing(things, key, value) {

    for (var i = 0; i < things.length; i++)
        if (things[i][key] == value)
            return things[i];

};

 

Votes

Translate

Translate

Report

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