Skip to main content
dublove
Brainiac
July 2, 2025
Answered

“findWhat: ‘@’” can't retrieve content in overflow text?

  • July 2, 2025
  • 1 reply
  • 1655 views
 If the character you're looking for is in the overflow text, findWhat won't help.
Any ideas?
  var queries = [
        { findWhat: '@', objectStyleName: "CapCenter"},
    ];

Maybe have the overflow text expand first in the same text box?

Correct answer rob day

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

1 reply

rob day
Community Expert
July 2, 2025

Try this, it searches the active document for @ symbols and returns them in an array

 

 

//the search results as an array
var res = getTextSearch("@")
alert(res.length + " @ Symbols found")
for (var i = 0; i < res.length; i++){
    alert(res[i].contents)
};


/**
* Gets results of a text search as an array 
* @ param text to search for 
* @ return an array of results
*/
function getTextSearch(fp){
    app.findTextPreferences = app.changeTextPreferences = app.findChangeTextOptions = null;
    app.findChangeTextOptions.properties = {includeHiddenLayers:true, includeLockedLayersForFind:true, includeLockedStoriesForFind:true, includeMasterPages:true} 
    app.findTextPreferences.findWhat = fp;
    return app.activeDocument.findText()
}

 


dublove
dubloveAuthor
Brainiac
July 2, 2025

Hi rob day~

I found this one too.Also you finished it.

 

I've been studying it for half a day.
I'd like to start by applying a CapC object style to the found text boxes. But I tried half a day without success.

 

I'm also trying to get the contents of the text box.


Still can't tell the hierarchy?
Or is the syntax wrong?

/**
by rob day
original site
https://community.adobe.com/t5/indesign-discussions/how-can-i-search-for-text-in-textframes-even-if-it-is-not-shown/m-p/15367877
**/

(function main() {
    var ra = grepSearch("jpg");
    //reverse loop
    for (var i = ra.length - 1; i > -1; i--) {
        //ra[i].properties = { pointSize: 35, leading: 40 }
        //var os = app.activeDocument.objectStyles.itemByName(capObjCStn);
        //alert(os.name);
        //ra[i].parent.textFrames[0].applyObjectStyle = os;
        ra[i].parent.properties = {
            appliedObjectStyle: app.activeDocument.objectStyles.item(capObjCStn)
        }
    };


    /**
    * Document Grep find returns an array of text objects
    * @ param f the find grep string 
    * @ return an array of found texts 
    */
    function grepSearch(f) {
        app.findGrepPreferences = app.changeGrepPreferences = app.findChangeGrepOptions = null;
        app.findChangeGrepOptions.properties = app.findChangeGrepOptions.properties = { includeFootnotes: true, includeHiddenLayers: true, includeMasterPages: true, wholeWord: false }
        app.findGrepPreferences.findWhat = f;
        return app.activeDocument.findGrep()
    }
})();

 

rob day
Community Expert
July 3, 2025

Hi @rob day 

I'm trying to remove the @. in the title note. The following sentence
tf.contents.replace(/@/i, "");

I will, it turns out:
tf.contents = tf.contents.replace(/\@/gi, "");

 

But I don't know how this is case insensitive?
var res = getTextSearch("(?i)abc")
doesn't seem to work.

getTextSearch(); does not seem to support complex expressions.

thank you.


My getTextSearch(fp) function is searching for plain text not GREP. This searches for GREP:

 

/**
* Gets results of a text search as an array 
* @ param text to search for 
* @ 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()
}