Skip to main content
Known Participant
May 15, 2023
Answered

find and replace text wont work on long text

  • May 15, 2023
  • 3 replies
  • 4310 views

Hello

i have a psd file with about 40 artboards which are the same graphics/layers but in difrrent sizes

and i want the ability to change a pargraph across all artboards

but for some reason when even i try to paste a long paragraph into the "find and replace text" window, it wont paste it at all and leave the field empty.

i searched everywhere and didnt find that there are limitations to number of characters in this field

so what is the problem? and is there a fix?

 

i atached a sample psd file

and this is a demo for long text that wont paste instead of the legal text in the attached psd file:

"this is a long demo text that i cant seem to actully paste into find and replace tool in photoshop and this just ruins my intire process for building banners grid, which i have to be able to do in order to create grid for many banners who i need to produce"

 

thank you

lital

This topic has been closed for replies.
Correct answer Stephen Marsh
@Lital2252941669o3 wrote:

but i need the possibility to input a diffrent paragraph each time (i have 100 diffrent ones for 40 diffrent banner sizes)

is there a way to do this for a panel like the find and replace where i could input text?


 

OK, here is a new version using a single scriptUI dialog rather than two separate prompts:

 

/*
Unlimited Input Find & Replace.jsx
v1.0 - 17th May 2023, Stephen Marsh
https://community.adobe.com/t5/photoshop-ecosystem-discussions/find-and-replace-text-wont-work-on-long-text/td-p/13793461
*/

// Configure the text parameters to pass to the main window function
// Non breaking space character \u00A0 to avoid truncation on Win OS
findReplaceDialog("Find & Replace Interface v1.0", "Find:\u00A0", "Replace (No 255 Character Limit):\u00A0");

// Main function
function findReplaceDialog(promptTitle, promptString, promptString2) {
    try {

        // PROMPT WINDOW
        var promptWindow = new Window("dialog");
        promptWindow.text = promptTitle;
        /*
        var gra = dialog.graphics;
        //var uiBrush = gra.newBrush(gra.BrushType.SOLID_COLOR, [0.3, 0.3, 0.3, 1]);
        var uiBrush = gra.newBrush(gra.BrushType.THEME_COLOR, "appDialogBackground"
        gra.backgroundColor = uiBrush;
        */
        promptWindow.preferredSize.width = 340;
        promptWindow.preferredSize.height = 260;
        promptWindow.orientation = "column";
        promptWindow.alignChildren = ["left", "top"];
        promptWindow.spacing = 15;
        promptWindow.margins = 20;

        // FIELD GROUP
        var fieldGroup = promptWindow.add("group", undefined, {
            name: "fieldGroup"
        });
        fieldGroup.orientation = "column";
        fieldGroup.alignChildren = ["left", "center"];
        fieldGroup.spacing = 5;
        fieldGroup.margins = 0;

        // FIND PROMPT FIELD LABEL
        var promptLabel = fieldGroup.add("statictext", undefined, undefined, {
            name: "promptLabel"
        });
        promptLabel.text = promptString;
        promptLabel.preferredSize.height = 25;
        promptLabel.preferredSize.width = 300;
        // Option - swap undefined for "bold" if required
        promptLabel.graphics.font = ScriptUI.newFont("dialog", undefined, 13);
        /*
        // TEXT COLOR
        promptLabel.graphics.foregroundColor = promptLabel.graphics.newPen(promptLabel.graphics.PenType.SOLID_COLOR, [1, 1, 1], 1);
        */

        // FIND PROMPT FIELD
        var promptField = fieldGroup.add('edittext {properties: {name: "promptField", multiline: true, scrollable: true}}');
        promptField.helpTip = "Find:";
        // Default text
        promptField.text = "";
        //promptField.preferredSize.width = 300;
        promptField.alignment = ["fill","center"];
        promptField.preferredSize.height = 75;
        promptField.active = true;

        // REPLACE PROMPT FIELD LABEL
        var promptLabel2 = fieldGroup.add("statictext", undefined, undefined, {
            name: "promptLabel2"
        });
        promptLabel2.text = promptString2;
        promptLabel2.preferredSize.height = 25;
        promptLabel2.preferredSize.width = 300;
        // Option - swap undefined for "bold" if required
        promptLabel2.graphics.font = ScriptUI.newFont("dialog", undefined, 13);
        /*
        // TEXT COLOR
        promptLabel.graphics.foregroundColor = promptLabel.graphics.newPen(promptLabel.graphics.PenType.SOLID_COLOR, [1, 1, 1], 1);
        */

        // REPLACE PROMPT FIELD
        var promptField2 = fieldGroup.add('edittext {properties: {name: "promptField2", multiline: true, scrollable: true}}');
        promptField2.helpTip = "Replace:";
        // Default text
        promptField2.text = "";
        //promptField2.preferredSize.width = 300;
        promptField2.alignment = ["fill","center"];
        promptField2.preferredSize.height = 75;

        // BUTTON GROUP
        var buttonGroup = promptWindow.add("group", undefined, {
            name: "buttonGroup"
        });
        buttonGroup.orientation = "row";
        buttonGroup.alignChildren = ["left", "top"];
        buttonGroup.spacing = 0;
        buttonGroup.margins = 0;

        // CANCEL BUTTON
        var cancelButton = buttonGroup.add("button", undefined, undefined, {
            name: "cancelButton"
        });
        cancelButton.text = "Cancel";
        cancelButton.justify = "left";

        // OK BUTTON
        var okButton = buttonGroup.add("button", undefined, undefined, {
            name: "okButton"
        });
        okButton.text = "OK";
        okButton.justify = "left";

        // RENDER THE WINDOW & OK BUTTON ACTION
        if (promptWindow.show() === 1 && (promptField.text !== "") && (promptField2.text !== "")) {
            // Code to run on OK
            findReplaceText();
        } else {
            //app.beep();
            //alert("Script cancelled!");
        }

        // FUNCTION TO RUN WHEN THE OK BUTTON IS PRESSED
        function findReplaceText() {
            var s2t = function (s) {
                return app.stringIDToTypeID(s);
            };
            var descriptor = new ActionDescriptor();
            var descriptor2 = new ActionDescriptor();
            var reference = new ActionReference();
            reference.putProperty(s2t("property"), s2t("replace"));
            reference.putEnumerated(s2t("textLayer"), s2t("ordinal"), s2t("allEnum"));
            descriptor.putReference(s2t("null"), reference);
            descriptor2.putString(s2t("find"), promptField.text); // Find
            descriptor2.putString(s2t("replace"), promptField2.text); // Replace
            descriptor2.putBoolean(s2t("checkAll"), true);
            descriptor2.putBoolean(s2t("forward"), true);
            descriptor2.putBoolean(s2t("caseSensitive"), false);
            descriptor2.putBoolean(s2t("wholeWord"), false);
            descriptor2.putBoolean(s2t("ignoreAccents"), true);
            descriptor.putObject(s2t("using"), s2t("findReplace"), descriptor2);
            executeAction(s2t("replace"), descriptor, DialogModes.NO);
        }
    
    } catch (err) {
        alert("There was an unexpected error!" + "\r" + err + ' ' + err.line);
    }
}

 

 

3 replies

Stephen Marsh
Community Expert
Stephen MarshCommunity ExpertCorrect answer
Community Expert
May 16, 2023
@Lital2252941669o3 wrote:

but i need the possibility to input a diffrent paragraph each time (i have 100 diffrent ones for 40 diffrent banner sizes)

is there a way to do this for a panel like the find and replace where i could input text?


 

OK, here is a new version using a single scriptUI dialog rather than two separate prompts:

 

/*
Unlimited Input Find & Replace.jsx
v1.0 - 17th May 2023, Stephen Marsh
https://community.adobe.com/t5/photoshop-ecosystem-discussions/find-and-replace-text-wont-work-on-long-text/td-p/13793461
*/

// Configure the text parameters to pass to the main window function
// Non breaking space character \u00A0 to avoid truncation on Win OS
findReplaceDialog("Find & Replace Interface v1.0", "Find:\u00A0", "Replace (No 255 Character Limit):\u00A0");

// Main function
function findReplaceDialog(promptTitle, promptString, promptString2) {
    try {

        // PROMPT WINDOW
        var promptWindow = new Window("dialog");
        promptWindow.text = promptTitle;
        /*
        var gra = dialog.graphics;
        //var uiBrush = gra.newBrush(gra.BrushType.SOLID_COLOR, [0.3, 0.3, 0.3, 1]);
        var uiBrush = gra.newBrush(gra.BrushType.THEME_COLOR, "appDialogBackground"
        gra.backgroundColor = uiBrush;
        */
        promptWindow.preferredSize.width = 340;
        promptWindow.preferredSize.height = 260;
        promptWindow.orientation = "column";
        promptWindow.alignChildren = ["left", "top"];
        promptWindow.spacing = 15;
        promptWindow.margins = 20;

        // FIELD GROUP
        var fieldGroup = promptWindow.add("group", undefined, {
            name: "fieldGroup"
        });
        fieldGroup.orientation = "column";
        fieldGroup.alignChildren = ["left", "center"];
        fieldGroup.spacing = 5;
        fieldGroup.margins = 0;

        // FIND PROMPT FIELD LABEL
        var promptLabel = fieldGroup.add("statictext", undefined, undefined, {
            name: "promptLabel"
        });
        promptLabel.text = promptString;
        promptLabel.preferredSize.height = 25;
        promptLabel.preferredSize.width = 300;
        // Option - swap undefined for "bold" if required
        promptLabel.graphics.font = ScriptUI.newFont("dialog", undefined, 13);
        /*
        // TEXT COLOR
        promptLabel.graphics.foregroundColor = promptLabel.graphics.newPen(promptLabel.graphics.PenType.SOLID_COLOR, [1, 1, 1], 1);
        */

        // FIND PROMPT FIELD
        var promptField = fieldGroup.add('edittext {properties: {name: "promptField", multiline: true, scrollable: true}}');
        promptField.helpTip = "Find:";
        // Default text
        promptField.text = "";
        //promptField.preferredSize.width = 300;
        promptField.alignment = ["fill","center"];
        promptField.preferredSize.height = 75;
        promptField.active = true;

        // REPLACE PROMPT FIELD LABEL
        var promptLabel2 = fieldGroup.add("statictext", undefined, undefined, {
            name: "promptLabel2"
        });
        promptLabel2.text = promptString2;
        promptLabel2.preferredSize.height = 25;
        promptLabel2.preferredSize.width = 300;
        // Option - swap undefined for "bold" if required
        promptLabel2.graphics.font = ScriptUI.newFont("dialog", undefined, 13);
        /*
        // TEXT COLOR
        promptLabel.graphics.foregroundColor = promptLabel.graphics.newPen(promptLabel.graphics.PenType.SOLID_COLOR, [1, 1, 1], 1);
        */

        // REPLACE PROMPT FIELD
        var promptField2 = fieldGroup.add('edittext {properties: {name: "promptField2", multiline: true, scrollable: true}}');
        promptField2.helpTip = "Replace:";
        // Default text
        promptField2.text = "";
        //promptField2.preferredSize.width = 300;
        promptField2.alignment = ["fill","center"];
        promptField2.preferredSize.height = 75;

        // BUTTON GROUP
        var buttonGroup = promptWindow.add("group", undefined, {
            name: "buttonGroup"
        });
        buttonGroup.orientation = "row";
        buttonGroup.alignChildren = ["left", "top"];
        buttonGroup.spacing = 0;
        buttonGroup.margins = 0;

        // CANCEL BUTTON
        var cancelButton = buttonGroup.add("button", undefined, undefined, {
            name: "cancelButton"
        });
        cancelButton.text = "Cancel";
        cancelButton.justify = "left";

        // OK BUTTON
        var okButton = buttonGroup.add("button", undefined, undefined, {
            name: "okButton"
        });
        okButton.text = "OK";
        okButton.justify = "left";

        // RENDER THE WINDOW & OK BUTTON ACTION
        if (promptWindow.show() === 1 && (promptField.text !== "") && (promptField2.text !== "")) {
            // Code to run on OK
            findReplaceText();
        } else {
            //app.beep();
            //alert("Script cancelled!");
        }

        // FUNCTION TO RUN WHEN THE OK BUTTON IS PRESSED
        function findReplaceText() {
            var s2t = function (s) {
                return app.stringIDToTypeID(s);
            };
            var descriptor = new ActionDescriptor();
            var descriptor2 = new ActionDescriptor();
            var reference = new ActionReference();
            reference.putProperty(s2t("property"), s2t("replace"));
            reference.putEnumerated(s2t("textLayer"), s2t("ordinal"), s2t("allEnum"));
            descriptor.putReference(s2t("null"), reference);
            descriptor2.putString(s2t("find"), promptField.text); // Find
            descriptor2.putString(s2t("replace"), promptField2.text); // Replace
            descriptor2.putBoolean(s2t("checkAll"), true);
            descriptor2.putBoolean(s2t("forward"), true);
            descriptor2.putBoolean(s2t("caseSensitive"), false);
            descriptor2.putBoolean(s2t("wholeWord"), false);
            descriptor2.putBoolean(s2t("ignoreAccents"), true);
            descriptor.putObject(s2t("using"), s2t("findReplace"), descriptor2);
            executeAction(s2t("replace"), descriptor, DialogModes.NO);
        }
    
    } catch (err) {
        alert("There was an unexpected error!" + "\r" + err + ' ' + err.line);
    }
}

 

 

Known Participant
May 16, 2023

ok so i tried this on the demo file i sent you and it worked perfect

but when i try it on the real file which has 40 artboards and the text is in hebrew

i get an error message:

do you maybe know why this is hapening?

i did this one on the same mac and same photoshop as before

Known Participant
May 17, 2023

It could be related to the English vs. Hebrew text, I don't know...

 

You could install the ScriptingListener plug-in:

 

https://helpx.adobe.com/au/photoshop/kb/downloadable-plugins-and-content.html

 

And use that to capture the find and replace step as JavaScript code.

 

Then provide the code for me to update.


ok so i tried to install the scriptlistener and it failed (it just didnt do the log file) but than i restart my mac and your script works amazingly now without changing anything

so again thank you very very much

you really helped me

Stephen Marsh
Community Expert
Community Expert
May 16, 2023

As @ktaki informs us that this is a GUI limitation, we can do away with the native GUI:

 

Select one of the "put the legal text here" text layers, then run this script:

 

#target photoshop

var findText = "put the legal text here";

var replaceText = "this is a long demo text that i cant seem to actully paste into find and replace tool in photoshop and this just ruins my intire process for building banners grid, which i have to be able to do in order to create grid for many banners who i need to produce";

var idreplace = stringIDToTypeID("replace");
    var desc483 = new ActionDescriptor();
    var idnull = stringIDToTypeID( "null" );
        var ref135 = new ActionReference();
        var idproperty = stringIDToTypeID( "property" );
        var idreplace = stringIDToTypeID( "replace" );
        ref135.putProperty( idproperty, idreplace );
        var idtextLayer = stringIDToTypeID( "textLayer" );
        var idordinal = stringIDToTypeID( "ordinal" );
        var idallEnum = stringIDToTypeID( "allEnum" );
        ref135.putEnumerated( idtextLayer, idordinal, idallEnum );
    desc483.putReference( idnull, ref135 );
    var idusing = stringIDToTypeID( "using" );
        var desc484 = new ActionDescriptor();
        var idfind = stringIDToTypeID( "find" );
        desc484.putString( idfind, findText );
        var idreplace = stringIDToTypeID( "replace" );
        desc484.putString( idreplace, replaceText );
        var idcheckAll = stringIDToTypeID( "checkAll" );
        desc484.putBoolean( idcheckAll, true );
        var idforward = stringIDToTypeID( "forward" );
        desc484.putBoolean( idforward, true );
        var idcaseSensitive = stringIDToTypeID( "caseSensitive" );
        desc484.putBoolean( idcaseSensitive, false );
        var idwholeWord = stringIDToTypeID( "wholeWord" );
        desc484.putBoolean( idwholeWord, false );
        var idignoreAccents = stringIDToTypeID( "ignoreAccents" );
        desc484.putBoolean( idignoreAccents, true );
    var idfindReplace = stringIDToTypeID( "findReplace" );
    desc483.putObject( idusing, idfindReplace, desc484 );
executeAction( idreplace, desc483, DialogModes.NO );
app.beep();

 

 

For a very quick GUI, you could replace the first two static variable lines with prompts, such as:

 

var findText = prompt("Find text:", "put the legal text here");

var replaceText = prompt("Replace text:", "this is a long demo text that i cant seem to actully paste into find and replace tool in photoshop and this just ruins my intire process for building banners grid, which i have to be able to do in order to create grid for many banners who i need to produce");

 

 

https://prepression.blogspot.com/2017/11/downloading-and-installing-adobe-scripts.html

Known Participant
May 16, 2023

thank you but i tried the script and got an error

Stephen Marsh
Community Expert
Community Expert
May 16, 2023

 

@Lital2252941669o3 

 

You didn't read my blogpost carefully enough, you saved the code as an RTF (rich text format) – not as a plain text format TXT file.

 

Mac: Apple TextEdit (ensure that the Format menu is set to Plain Text mode, not Rich Text mode)

 

 

Bojan Živković11378569
Community Expert
Community Expert
May 16, 2023

No problem on my side. I am on Windows running 24.4.1 Photoshop. Wait someone with Mac to confirm. What is your Ps version by the way? And if you can change font to something that everyone have installed like Arial to skip trouble replacing text and missing Glyphs.

Adobe Employee
May 16, 2023
The maximum number allowed in the "Find What" and "Change To" fields is 255 characters. The difference in behaviors of Mac and Windows is that on Windows text can be pasted up to 255 characters then the rest will be truncated while on Mac it does not allow pasting any text when you try to paste text that has more than 255 characters.