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

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

Guide ,
Nov 12, 2025 Nov 12, 2025

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.

0666.png

TOPICS
How to , Scripting
177
Translate
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 2 Correct answers

Community Expert , Nov 12, 2025 Nov 12, 2025

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
Community Expert , Nov 12, 2025 Nov 12, 2025

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")
    }
} 

 

Screen Shot 28.png

 

Screen Shot 29.png

Translate
Community Expert ,
Nov 12, 2025 Nov 12, 2025

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
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 ,
Nov 12, 2025 Nov 12, 2025

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")
    }
} 

 

Screen Shot 28.png

 

Screen Shot 29.png

Translate
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
Guide ,
Nov 12, 2025 Nov 12, 2025

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
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 ,
Nov 12, 2025 Nov 12, 2025

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);
}

 

Screen Shot 30.png

Translate
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 ,
Nov 12, 2025 Nov 12, 2025

I'm still confused @dublove. The code I posted *exactly* does what your re-worded post asks for. Did you try it? It gives you the `textFrames` array which has all the text frames you ask for. Isn't that right?

- Mark

Translate
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
Guide ,
Nov 12, 2025 Nov 12, 2025

 Sorry @m1b

 

I didn't notice it at first , I forget to test when I get busy.

This is fantastic.

Compact and efficient.

Thank you very much.

 

Translate
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
Guide ,
Nov 12, 2025 Nov 12, 2025

When the cursor is inside a table, multiple scenarios are possible. This check seems less accurate.

var item=doc.selcection[0];
if(“Table” == item.parent.parent.constructor.name)
Translate
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 ,
Nov 12, 2025 Nov 12, 2025

The hasOwnProperty('parentTextFrames') method that @m1b  and I'm using is shorter and probably works better to test if the selection is text.

Translate
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 ,
Nov 12, 2025 Nov 12, 2025

So if the curser is inside a table, what do you want the script to return? The text frame that contains the CELL of the selected text or insertion point? Or every text frame that contains the whole table?

 

We must be VERY specific, because the code will be different.

Translate
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
Guide ,
Nov 13, 2025 Nov 13, 2025

@m1b 

I've shifted my approach.
My function now only accepts objects.

Previously, I only needed to check the selection status and convert the selection area into an object target.

 

There are three scenarios:
Cursor in text.
Cursor in table.
Selected image (white arrow pair and black arrow).
Plus geometric shapes.

 

Your original getTextFrames implementation sometimes included unexpected cases, complicating matters.
Meanwhile, getTables occasionally seemed to omit elements, failing to capture everything.

I've reverted to the most basic validation approach.
For instance, with text boxes, it only returns the parent text box.

Translate
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 ,
Nov 13, 2025 Nov 13, 2025

It is difficult because you do not carefully list all your cases for us.

 

getTextFrames deliberately tries to get every possible text frame from the input. If you want something else you must be very specific.

 

If getTables fails for some tables I would love to have a test document showing it, so I can improve the function.

 

Anyway a very basic implementation is fine, if you understand it's limitations. I think you are learning a lot from this process. Keep it up!

Translate
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
Guide ,
Nov 13, 2025 Nov 13, 2025
LATEST

I'm reposting this question to clarify the structure.

Translate
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