Skip to main content
dublove
Legend
Nov 12, 2025 10:12 AM UTC
Answered

How do I know I've selected all text in the entire article?

Hi everyone.
When my cursor is in the current text box, it looks like this.
At this point, my current target of action, sel, is the current text box.

var doc = app.activeDocument;
var item = doc.selection[0];
var items;
alert(item.constructor.name);

if (
    ("InsertionPoint" == item.constructor.name
        || "Character" == item.constructor.name
        || "Text" == item.constructor.name
        || "Word" == item.constructor.name
        || "Paragraph" == item.constructor.name)
    && "Table" != item.parent.parent.constructor.name
) {
    items = item.parentTextFrames;
    sel = items;
    alert(items);

If I select all content in the current article,
Now, I want my selection target (sel) to be every text Frame of this article.

 

To be more precise, my target is the text box containing the selected text.
For example, if an article has 10 text boxes and I select content from boxes 3 through 6, then my target objects are Frame3, Frame4, Frame5, and Frame6.


How can I represent this with code?

Thank you.

rob day
rob dayCorrect answer
Community Expert
Nov 12, 2025 11:18 AM UTC

If I've selected all text in the entire article,

 

Hi @dublove , You can check if the selection’s length matches the stories lenght like this:

 
var s = app.activeDocument.selection[0]

if (s.hasOwnProperty('parentTextFrames')) {
    if (s.insertionPoints.length === s.parent.insertionPoints.length) {
        alert("All text is selected")
    } else {
        alert("All text is not selected")
    }
} 

 

 

12 replies

rob day
Community Expert
rob dayCommunity ExpertCorrect answer
Community Expert
Nov 12, 2025 11:18 AM UTC

If I've selected all text in the entire article,

 

Hi @dublove , You can check if the selection’s length matches the stories lenght like this:

 
var s = app.activeDocument.selection[0]

if (s.hasOwnProperty('parentTextFrames')) {
    if (s.insertionPoints.length === s.parent.insertionPoints.length) {
        alert("All text is selected")
    } else {
        alert("All text is not selected")
    }
} 

 

 

Translate
dublove
dubloveAuthor
Legend
Nov 12, 2025 1:33 PM UTC

Hi @m1b  @rob day 

Sorry, I didn't express myself clearly.
I've updated the original post.
It's basically what Rob Day meant.

Also, about the code I provided above—
why does  " item.parentTextFrames" only display the current text frame(only 1 text frame)? It doesn't include all the text from the stories. 

Translate
rob day
Community Expert
Community Expert
Nov 12, 2025 2:36 PM UTC

item.parentTextFrames is an array—here if I get the array’s length the result is 2 because the selection is contained by 2 text frames:

 

var doc = app.activeDocument;
var item = doc.selection[0];
var items;

if (
    ("InsertionPoint" == item.constructor.name
        || "Character" == item.constructor.name
        || "Text" == item.constructor.name
        || "Word" == item.constructor.name
        || "Paragraph" == item.constructor.name)
    && "Table" != item.parent.parent.constructor.name
){
    items = item.parentTextFrames;
    alert(items.length);
}

 

Translate
m1b
Community Expert
Community Expert
Nov 12, 2025 10:22 AM UTC

Hi @dublove I don't understand you exactly. Does this help?

var doc = app.activeDocument;
var text = doc.selection[0];

var textFrames = [];

if (text && text.hasOwnProperty('parentTextFrames'))
    textFrames = text.parentTextFrames;

alert('You have selected text spanning ' + textFrames.length + ' text frames.');
Translate