It's possibly using scripting, but in this particular case I would use GREP. Search for
and make sure the Change To text field is totally empty. Set the Change To formatting to your paragraph style
The GREP expression is
^ Start Of Paragraph
[ Begin of Or-group
\w Any 'word' character (A..Z, a..z, 0..9; also includes accented and non-Latin alphabets)
\- A regular hyphen
] End of Or-group
+ Repeat the previous command (in this case, the Or-match) as much as possible
$ End of Paragraph
The hyphen needs to be added because it's not a 'word' character.
This construction will find any and all entire paragraphs that consist of a single word (including any hyphens); its also possible to search for 'up to n words', paragraphs starting with a number ("1.0 Introduction"), and even paragraphs-that-don't-end-with-a-period.
It's not possible to search for 'one-line paragraphs' -- specifying the number of lines is not an option in InDesign. Now that would need a script.
Here is a simple script to scan for one-liners in your current story (the text thread that contains the blinking cursor):
p = app.selection.parentStory.paragraphs; for (a=0; a<p.length; a++) if (p[a].lines.length == 1) p[a].appliedParagraphStyle = "myHeaderStyle";
A line-by-line breakdown:
Ln 1. Store a reference to all "paragraphs" in the parentStory of the current selection (meaning, the selection itself is something like "InsertionPoint" -- the cursor position -- and its parentStory property points straight away to the entire text -- the Story. The Story has a collection of Paragraphs, and that's what we want.)
Ln 3. Each paragraph in the story has a property named 'lines', pointing to an array of each separate text line in that paragraph. Since it's an array, it has a length, and if its length equals 1, there is only one line in that paragraph. ¿Si?
Ln 4. Each paragraph also has a property named "appliedParagraphStyle". When asked what value it has, it will return a [ParagraphStyleObject], rather than a simple name, but you can set it to a new value by directly assigning it a new name -- in this case, "myHeaderStyle", you need to set it to the style name you are using.
Thank you very much, the GREP search worked perfectly. One more question,
is there a good GREP reference available online? I'd like to
learn more about using it.
Peter Kahrel's O'Reilly e-book "GREP in InDesign" specifically targets InDesign, and it's cheap, too! (A cent short of a tenner.)
Updated: August 2010. Author Peter Kahrel updated this Short Cut to cover InDesign CS5.
Yes. Peter has some great examples there!
Thank you, I'll look into it.
From: "[Jongware]" <email@example.com>
Date: Sun, 29 Aug 2010 05:28:54 -0600
To: George Dufford <firstname.lastname@example.org>
Peter Kahrel's O'Reilly e-book "http://oreilly.com/catalog/9780596156015/"
specifically targets InDesign, and it's cheap, too! (A cent short of a
>> Updated: August 2010. Author Peter Kahrel updated this Short Cut to cover
>> InDesign CS5.
RegExr looks cool Thanks for that link!
(AIR is desktop. Online is simply Flash.)
Here's another nice tool for playing with GREP as well (it has InDesign specific features):
Harbs, thanks for the link!