Skip to main content
dublove
Legend
August 31, 2025
Answered

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

  • August 31, 2025
  • 1 reply
  • 291 views

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

Correct answer rob day

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

 

 

 

1 reply

rob day
Community Expert
rob dayCommunity ExpertCorrect answer
Community Expert
August 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()
}

 

 

 

dublove
dubloveAuthor
Legend
August 31, 2025

Hi rob day.

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

Also, I had the wrong search scope.