Skip to main content
Participant
June 12, 2008
Question

Help with script to find indented paragraphs and apply style to them

  • June 12, 2008
  • 3 replies
  • 578 views
Hi!

I'd be most grateful if anyone who might have it, would provide me with a javascript that finds paragraphs with a "less than" first line indent and changes that paragpraph to a specified paragraph style.

I have a long OCR-text with varying first lien indents that i need to format.

Any advice is also welcome!

TIA

Jacob Blomqvist, Stockholm, Sweden.
jacob@grafem.se
This topic has been closed for replies.

3 replies

Participant
June 13, 2008
Hi Peter!
It´s perfect, I'm much obliged to you!

/Jacob
Participant
June 13, 2008
<DIV><FONT face=Arial size=2>Peter Kahrel</FONT></DIV><br /><DIV><FONT face=Arial size=2></FONT> </DIV><br /><DIV><FONT face=Arial size=2>Oh, here it comes as a mail, too.</FONT></DIV><br /><DIV><FONT face=Arial size=2>I repeat what I wrote in the Forum: "Thanks a lot <br />Peter!". It's very useful too me!</FONT></DIV><br /><DIV><FONT face=Arial size=2></FONT> </DIV><br /><DIV><FONT face=Arial size=2>Best regards,</FONT></DIV><br /><DIV><FONT face=Arial size=2></FONT> </DIV><br /><DIV><FONT face=Arial size=2>Jacob Blomqvist, Stockholm</FONT></DIV><br /><BLOCKQUOTE <br />style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px"><br /> <DIV style="FONT: 10pt arial">----- Original Message ----- </DIV><br /> <DIV <br /> style="BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: black"><B>From:</B> <br /> <A title=member@adobeforums.com href="mailto:member@adobeforums.com">Peter <br /> Kahrel</A> </DIV><br /> <DIV style="FONT: 10pt arial"><B>To:</B> <A <br /> title=adobe.scripting.indesign@adobeforums.com <br /> href="mailto:adobe.scripting.indesign@adobeforums.com">adobe.scripting.indesign@adobeforums.com</A> <br /> </DIV><br /> <DIV style="FONT: 10pt arial"><B>Sent:</B> Thursday, June 12, 2008 8:44 <br /> PM</DIV><br /> <DIV style="FONT: 10pt arial"><B>Subject:</B> Re: Help with script to find <br /> indented paragraphs and apply style to them</DIV><br /> <DIV><BR></DIV>A new message was posted by Peter Kahrel in <BR><BR><B>InDesign <br /> Scripting</B> --<BR>  Help with script to find indented paragraphs <br /> and apply style to them<BR><BR>I often use (a slight variaton of) this script: <br /><PRE>ps = app.activeDocument.paragraphStyles.item ('default'); <br />s = app.activeDocument.stories; <br />for (i = 0; i &lt; s.length; i++) <br />   { <br />   p = s.paragraphs; <br />   for (j = 0; j &lt; p.length; j++) <br />      if (p.firstLineIndent &lt; '10 pt') <br />         p.applyParagraphStyle (ps, false) <br />   }</PRE><BR><BR>This is for CS3: CS2 needs applyStyle instead <br /> of applyParagraphStyle. Two changes you need to make are the name of the style <br /> you want to apply in the first line, and the limit below which that style is <br /> applied in line 7. <BR><BR>Peter <BR><BR><br /> <HR align=left width=200><br /> View/reply at <A href="http://www.adobeforums.com/webx?13@@.59b58396/0">Help <br /> with script to find indented paragraphs and apply style to them</A><BR>Replies <br /> by email are OK.<BR>Use the <A <br /> href="http://www.adobeforums.com/webx?280@@.59b58396!folder=.eea52bc">unsubscribe</A> <br /> form to cancel your email subscription.<BR><BR></BLOCKQUOTE>
Peter Kahrel
Community Expert
Community Expert
June 12, 2008
I often use (a slight variaton of) this script:
ps = app.activeDocument.paragraphStyles.item ('default');

s = app.activeDocument.stories;
for (i = 0; i < s.length; i++)
{
p = s.paragraphs;
for (j = 0; j < p.length; j++)
if (p.firstLineIndent < '10 pt')
p.applyParagraphStyle (ps, false)
}


This is for CS3: CS2 needs applyStyle instead of applyParagraphStyle. Two changes you need to make are the name of the style you want to apply in the first line, and the limit below which that style is applied in line 7.

Peter