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

How to determine which text box is currently selected: the first, middle, or last one?

Guide ,
Aug 21, 2025 Aug 21, 2025

Ignore the overflow for now.
I divided all textFram of the Story into 3 categories:
A: The first text box.
B: The middle text box.
C: The last text box.

How can I determine which category (A, B, or C) the currently selected text box belongs to?

 

8802.png

TOPICS
How to , Scripting
373
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 , Aug 22, 2025 Aug 22, 2025

Something like the following would work

var sel = app.selection[0]
if (sel.constructor.name != "TextFrame") {
	alert("Selection is not a textframe")
	exit()
}
if(sel.nextTextFrame == null && sel.previousTextFrame == null)
    alert("You selected the one and only frame")
if(sel.nextTextFrame != null && sel.previousTextFrame == null)
	alert("You selected the first frame")
if(sel.nextTextFrame != null && sel.previousTextFrame != null)
	alert("You selected the frame in the middle")
if(sel.nextTextFr
...
Translate
Community Expert , Aug 26, 2025 Aug 26, 2025

HI @dublove ,

all your text frames ( other page items as well ) have a unique ID value.

So you could determine all the text frames' id values of a given story and compare the id value of the one of your selection to a specific one of the text frames of a story:

 

var selectedTextFrame = app.selection[0] ;
var idOfSelectedTextFrame = selectedTextFrame.id ;

var parentStory = selectedTextFrame.parentStory ;

var allTextContainersArray = parentStory.textContainers ;

for( var n=0; n < allTextContai
...
Translate
Community Expert ,
Aug 21, 2025 Aug 21, 2025

This get the 3 text frames of story 1. The 3rd text frame’s overflows returns true

 

//A collection of the document’s stories
var s = app.activeDocument.stories;

//the parentTextFrames of the first story’s text—3 in this case
var fs = s[0].texts[0].parentTextFrames
$.writeln(fs.length)


for (var i = 0; i < fs.length; i++){
    if (i == 0) {
        $.writeln("This is the first text frame, overflows are " + fs[0].overflows)
    } else if (i == 1){
        $.writeln("This is the second text frame, overflows are " + fs[1].overflows)
    } else if (i == 2){
        $.writeln("This is the third text frame, overflows are " + fs[2].overflows)
    }
};   

/*
returns:
3
This is the first text frame, overflows are false
This is the second text frame, overflows are false
This is the third text frame, overflows are true
 */

 

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 ,
Aug 21, 2025 Aug 21, 2025

Hi rob day.
It's not like this.

I need to determine whether the currently selected textFrame is the first, middle, or last one.

 

Sometimes there may be only one textFrame.

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 ,
Aug 22, 2025 Aug 22, 2025

Something like the following would work

var sel = app.selection[0]
if (sel.constructor.name != "TextFrame") {
	alert("Selection is not a textframe")
	exit()
}
if(sel.nextTextFrame == null && sel.previousTextFrame == null)
    alert("You selected the one and only frame")
if(sel.nextTextFrame != null && sel.previousTextFrame == null)
	alert("You selected the first frame")
if(sel.nextTextFrame != null && sel.previousTextFrame != null)
	alert("You selected the frame in the middle")
if(sel.nextTextFrame == null && sel.previousTextFrame != null)
    alert("You selected the last frame")

-Manan

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 ,
Aug 22, 2025 Aug 22, 2025

That's it.
previousTextFrame
nextTextFrame

Manan Joshi  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 ,
Aug 22, 2025 Aug 22, 2025

@rob day  @m1b  I corrected my initial question.

II thought of a way to determine this based on three different scenarios.
However, it still seems impossible to determine which one I currently selected from fs[i].

 

The loop can only determine the order of the text boxes, but it cannot determine which text box is currently selected.

Is it possible to use A\. .\Z to determine this?

If A\. or .\Z cannot be found, it is the textFrame in the middle. I only need these three situations.
I don't know how to do this.

 

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 ,
Aug 26, 2025 Aug 26, 2025

HI @dublove ,

all your text frames ( other page items as well ) have a unique ID value.

So you could determine all the text frames' id values of a given story and compare the id value of the one of your selection to a specific one of the text frames of a story:

 

var selectedTextFrame = app.selection[0] ;
var idOfSelectedTextFrame = selectedTextFrame.id ;

var parentStory = selectedTextFrame.parentStory ;

var allTextContainersArray = parentStory.textContainers ;

for( var n=0; n < allTextContainersArray.length; n++ )
{
	if( allTextContainersArray[n].id == idOfSelectedTextFrame )
	{
		alert( "Selected frame found. Frame "+ (n+1) + " in the story is selected." );
		break;
	}
};

 

 

Or you could directly compare the text frames of the story to the one that is selected.

If you do this with the array of textContainers you first have to resolve the textContainer you like to compare with getElements() like below :

 

var selectedTextFrame = app.selection[0] ;

var parentStory = selectedTextFrame.parentStory ;

var allTextContainersArray = parentStory.textContainers ;

for( var n=0; n < allTextContainersArray.length; n++ )
{
	if( allTextContainersArray[n].getElements()[0] == selectedTextFrame )
	{
		alert( "Frame "+ (n+1) + " in the story is selected." );
		break;
	}
};

 

Regards,
Uwe Laubender
( Adobe Community Expert )

 

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 ,
Aug 26, 2025 Aug 26, 2025
LATEST

Hi Laubender.

Your answer makes sense too.

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