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

Is there a way to detect whether the currently selected text box contains a frame separator?

Guide ,
Aug 31, 2025 Aug 31, 2025

I want to check whether the currently selected frame contains a frame separator (~R) or a page separator (~P).
But it seems like I'm not getting any results.

var s = app.selection[0].texts[0].contents;
alert(s);

var what = "~R|~P"
var res = getGrepSearch(what, app.activeDocument);
alert(res);

function getGrepSearch(fp, s) {
    app.findGrepPreferences = app.changeGrepPreferences = app.findChangeGrepOptions = null;
    app.findChangeGrepOptions.properties = { includeHiddenLayers: true, includeLockedLayersForFind: true, includeLockedStoriesForFind: true, includeMasterPages: true }
    app.findGrepPreferences.findWhat = fp;
    //return app.findGrep()
    return s.findGrep()
}

2828.png

TOPICS
How to , Scripting
214
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 1 Correct answer

Community Expert , Aug 31, 2025 Aug 31, 2025

Set s to the text not the contents, try this:

 

//var s = app.selection[0].texts[0].contents;
//get the text frame not the contents
var s = app.selection[0].texts[0];

//returns an empty array
//var what = "~R|~P"
var what = "~R"

var res = getGrepSearch(what, s);
//the first found item
alert(res[0].contents)

function getGrepSearch(fp, s) {
    app.findGrepPreferences = app.changeGrepPreferences = app.findChangeGrepOptions = null;
    app.findChangeGrepOptions.properties = { includeHiddenLayer
...
Translate
Community Expert ,
Aug 31, 2025 Aug 31, 2025

Set s to the text not the contents, try this:

 

//var s = app.selection[0].texts[0].contents;
//get the text frame not the contents
var s = app.selection[0].texts[0];

//returns an empty array
//var what = "~R|~P"
var what = "~R"

var res = getGrepSearch(what, s);
//the first found item
alert(res[0].contents)

function getGrepSearch(fp, s) {
    app.findGrepPreferences = app.changeGrepPreferences = app.findChangeGrepOptions = null;
    app.findChangeGrepOptions.properties = { includeHiddenLayers: true, includeLockedLayersForFind: true, includeLockedStoriesForFind: true, includeMasterPages: true }
    app.findGrepPreferences.findWhat = fp;
    return s.findGrep()
}

 

Screen Shot 33.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 ,
Aug 31, 2025 Aug 31, 2025

Hi rob day.

Thank you very much.
So I needed to search the text.

Also, I had the wrong search scope.

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 ,
Sep 01, 2025 Sep 01, 2025

Hi @rob day 

Can't find it  Will it throw an error?
How to avoid it?

890.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 ,
Sep 01, 2025 Sep 01, 2025

If it can be found, no problem.
When there is no ~R to find, there is an error.

 

There's also alert(resP[0].contents); which pops up the image below.
But alert(resP[0].contents == "FRAME_BREAK"); pops up false.

 

Originally it was going to be
resP[0].contents==SpecialCharacters.FRAME_BREAK

dublove_0-1756733386111.jpeg

 

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 ,
Sep 01, 2025 Sep 01, 2025

You have to check if the array is empty:

 

var res = getGrepSearch(what, s);
if (res.length) {
	alert(res[0].contents)
} else {alert("Nothing Found")}
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 ,
Sep 01, 2025 Sep 01, 2025

Okay, I'll take your word for it. I'm voiding these.

//try {
// if (resR[0].contents == SpecialCharacters.FRAME_BREAK) {
// var fb = 1
// }
//}
//catch (e) { }
//try {
// if (resP[0].contents == SpecialCharacters.PAGE_BREAK) {
// var pb = 1
// }
//}
//catch (e) { } //}
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 ,
Sep 02, 2025 Sep 02, 2025
LATEST

@rob day 

I suddenly realized that  res.length  isn't always reliable either.
When the selected text box is a table, it will also throw an error.

 

At this point, var s = app.selection[0].texts[0]; is invalid.

Is there a way to make the function `getGrepSearch(fp, s)` support null?

dublove_0-1756881295642.jpeg

 

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 ,
Sep 01, 2025 Sep 01, 2025

For the error that is reported when it is not found.
I just catch it off, probably not a good idea.

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