Skip to main content
Inspiring
March 27, 2023
Answered

Script to change bulleted and numbered lists to text without converting the Paragraph Styles

  • March 27, 2023
  • 2 replies
  • 2859 views

I've seen a posts here about using the "Convert Bullets to Text" contextual option in text as well the method app.activeDocument.stories.everyItem().convertBulletsAndNumberingToText(); however neither is satifactory so ive been writing a script to change the copy in a document that has a bullet or number list style applied to converted text, but i'm having trouble figuring out how to script  going through the text, identifying the ones with specific paragraph styles ( there are 6 styles, all set within two layers of groupings: Body Styles [group] > Lists [group] > Bullet lvl 1 [style].

heres what ive tried to so, but i realized that it was converting the whole style not the text with the style.

 

var bul1 = doc.paragraphStyleGroups.itemByName( "Body Styles" ).paragraphStyleGroups.itemByName( "Lists" ).paragraphStyles.itemByName( "Bullet lvl 1" );
var bul2 = doc.paragraphStyleGroups.itemByName( "Body Styles" ).paragraphStyleGroups.itemByName( "Lists" ).paragraphStyles.itemByName( "Bullet lvl 2" );
var bul3 = doc.paragraphStyleGroups.itemByName( "Body Styles" ).paragraphStyleGroups.itemByName( "Lists" ).paragraphStyles.itemByName( "Bullet lvl 3" );
var num1 = doc.paragraphStyleGroups.itemByName( "Body Styles" ).paragraphStyleGroups.itemByName( "Lists" ).paragraphStyles.itemByName( "Num List lvl 1" );
var num2 = doc.paragraphStyleGroups.itemByName( "Body Styles" ).paragraphStyleGroups.itemByName( "Lists" ).paragraphStyles.itemByName( "Num List lvl 2" );
var num3 = doc.paragraphStyleGroups.itemByName( "Body Styles" ).paragraphStyleGroups.itemByName( "Lists" ).paragraphStyles.itemByName( "Num List lvl 3" );
 
// app.findTextPreferences.appliedParagraphStyle = bul1;
// bul1.convertBulletsAndNumberingToText();
// app.findTextPreferences.appliedParagraphStyle = bul2;
// bul2.convertBulletsAndNumberingToText();
// app.findTextPreferences.appliedParagraphStyle = bul3;
// bul3.convertBulletsAndNumberingToText();
// app.findTextPreferences.appliedParagraphStyle = num1;
// num1.convertBulletsAndNumberingToText();
// app.findTextPreferences.appliedParagraphStyle = num2;
// num2.convertBulletsAndNumberingToText();
// app.findTextPreferences.appliedParagraphStyle = num3;
// num3.convertBulletsAndNumberingToText();

// alert('Bullet lvl 1, 2, 3 and Number List lvl 1, 2, 3 converted to text.')
Correct answer Peter Kahrel

Rather than using InDesign's Find to look for styles, you may be better off cycling through paragraphs and checking their style names. Something like this:

 

par = doc.stories.everyItem().paragraphs.everyItem().getElements();
re = /(Bullet|Num) lvl [123]/;
for (i = 0; i < par.length; i++) {
  if (re.test (par[i].appliedParagraphStyle.name)) {
    // do something
  }
}

 

Peter

2 replies

Peter KahrelCommunity ExpertCorrect answer
Community Expert
March 28, 2023

Rather than using InDesign's Find to look for styles, you may be better off cycling through paragraphs and checking their style names. Something like this:

 

par = doc.stories.everyItem().paragraphs.everyItem().getElements();
re = /(Bullet|Num) lvl [123]/;
for (i = 0; i < par.length; i++) {
  if (re.test (par[i].appliedParagraphStyle.name)) {
    // do something
  }
}

 

Peter

Participating Frequently
May 23, 2024

Thanks for your help, Peter. Is there any way to tell the script to look inside all the tables inside a document?

Participating Frequently
March 14, 2025

@SweatersInSummer

 

There will be no errors - just nothing will happen. 

 


Hi, thanks for your answers. 

(My InDesign is in spanish) The error says: "unknown object type"

Inspiring
March 27, 2023

all those bottom lines are shown as commented out, i just forgot to un-comment them before posting but when active they convert the entire style to text, removing the list formatting entirely, and 

Robert at ID-Tasker
Legend
March 27, 2023

You can go back and re-edit your original post - there is no time limit.

 

Inspiring
March 28, 2023

I dont see any option to edit a post or comment, am i just completely missing it?