Answered
rob dayCorrect answer
Community Expert
Jul 3, 2025 4:02 PM UTC
If you chose images and text, how do you differentiate them and target only the text?
At the top, I don't know how to exclude non-textframe.
var doc = app.activeDocument,
item = doc.selection[0];
...
if (('Image' === item.constructor.name) ||
('TextFrame' === item.constructor.name)) {
try {
noselectMain());
}
if (!item){
selectMain());
}

You would have to loop thru the selected objects and check for text frames:
//a mixed selection
var sa = app.selection
for (var i = 0; i < sa.length; i++){
//get text frames in the selection
if (sa[i].constructor.name == "TextFrame") {
//a returned array of results fom the selected text
var res = getGrepSearch("@|AA|BB", sa[i])
alert(res)
for (var j = 0; j < res.length; j++){
//alert(res[j])
};
}
};
/**
* Gets results of a text search as an array
* @ param the Grep search string
* @ param the text to search
* @ return result as an array
*/
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()
}
