Skip to main content
Known Participant
September 12, 2018
Answered

Find Text and Replace with Carriage Return

  • September 12, 2018
  • 3 replies
  • 4594 views

Hi There,

I have dozens of PSD files that all have a specifc text that needs to be replace with a carriage return (new paragraph).

Does anyoen know what symbol or actions or .... to do this?

Thanks!

Ed

    This topic has been closed for replies.
    Correct answer JJMack

    A script should suffice.

    // replace text elements in type layers;

    // 2017, use it at your own risk;

    #target photoshop

    if (app.documents.length > 0) {

    for (var n = 0; n < app.documents.length; n++) {

    app.activeDocument = app.documents;

    app.activeDocument.suspendHistory("replace text", "main()")

    }

    };

    // the opertation;

    function main () {

    var myDocument = app.activeDocument;

    var theArray = [["b", "\r"]];

    for (var b = 0; b < theArray.length; b++) {

    replaceText (theArray[0], theArray[1])

    }

    };

    ////// reoplace text //////

    function replaceText (replaceThis, replaceWith) {

    try {

    // =======================================================

    var idreplace = stringIDToTypeID( "replace" );

        var desc22 = new ActionDescriptor();

        var idnull = charIDToTypeID( "null" );

            var ref3 = new ActionReference();

            var idPrpr = charIDToTypeID( "Prpr" );

            var idreplace = stringIDToTypeID( "replace" );

            ref3.putProperty( idPrpr, idreplace );

            var idTxLr = charIDToTypeID( "TxLr" );

            var idOrdn = charIDToTypeID( "Ordn" );

            var idAl = charIDToTypeID( "Al  " );

            ref3.putEnumerated( idTxLr, idOrdn, idAl );

        desc22.putReference( idnull, ref3 );

        var idUsng = charIDToTypeID( "Usng" );

            var desc23 = new ActionDescriptor();

            var idfind = stringIDToTypeID( "find" );

            desc23.putString( idfind, replaceThis );

            var idreplace = stringIDToTypeID( "replace" );

            desc23.putString( idreplace, replaceWith );

            var idcheckAll = stringIDToTypeID( "checkAll" );

            desc23.putBoolean( idcheckAll, true );

            var idFwd = charIDToTypeID( "Fwd " );

            desc23.putBoolean( idFwd, true );

            var idcaseSensitive = stringIDToTypeID( "caseSensitive" );

            desc23.putBoolean( idcaseSensitive, false );

            var idwholeWord = stringIDToTypeID( "wholeWord" );

            desc23.putBoolean( idwholeWord, false );

            var idignoreAccents = stringIDToTypeID( "ignoreAccents" );

            desc23.putBoolean( idignoreAccents, true );

        var idfindReplace = stringIDToTypeID( "findReplace" );

        desc22.putObject( idUsng, idfindReplace, desc23 );

    executeAction( idreplace, desc22, DialogModes.NO );

    } catch (e) {}

    };


    I changed you script to be more like the Op wanted to do insert a Carriage after some text.  So I added I prompt for the the text to find and a carriage return.  All open document text layers will be updated.

    // Add Carriage return after text string in type layers in all open documents

    // 2017, use it at your own risk;

    #target photoshop

    if (app.documents.length > 0) { 

       var findText = "";

       findText = prompt("Add Carriage Return after What",findText);

       if (findText!="") {

          for (var n = 0; n < app.documents.length; n++) { // process open documents

             app.activeDocument = app.documents;

             app.activeDocument.suspendHistory("replace text", "main(findText)")

          }

       }

    }; 

    // the opertation;

    function main (afterText) {

       var myDocument = app.activeDocument;

       //var theArray = [["b", "\, "a\n"]];

       var theArray = [[ afterText ,  afterText + "\r"]];

       for (var b = 0; b < theArray.length; b++) {

          replaceText (theArray[0], theArray[1])

       }

    };

    ////// reoplace text //////

    function replaceText (replaceThis, replaceWith) {

    try {

    // =======================================================

    var idreplace = stringIDToTypeID( "replace" );

        var desc22 = new ActionDescriptor();

        var idnull = charIDToTypeID( "null" );

            var ref3 = new ActionReference();

            var idPrpr = charIDToTypeID( "Prpr" );

            var idreplace = stringIDToTypeID( "replace" );

            ref3.putProperty( idPrpr, idreplace );

            var idTxLr = charIDToTypeID( "TxLr" );

            var idOrdn = charIDToTypeID( "Ordn" );

            var idAl = charIDToTypeID( "Al  " );

            ref3.putEnumerated( idTxLr, idOrdn, idAl );

        desc22.putReference( idnull, ref3 );

        var idUsng = charIDToTypeID( "Usng" );

            var desc23 = new ActionDescriptor();

            var idfind = stringIDToTypeID( "find" );

            desc23.putString( idfind, replaceThis );

            var idreplace = stringIDToTypeID( "replace" );

            desc23.putString( idreplace, replaceWith );

            var idcheckAll = stringIDToTypeID( "checkAll" );

            desc23.putBoolean( idcheckAll, true );

            var idFwd = charIDToTypeID( "Fwd " );

            desc23.putBoolean( idFwd, true );

            var idcaseSensitive = stringIDToTypeID( "caseSensitive" );

            desc23.putBoolean( idcaseSensitive, false );

            var idwholeWord = stringIDToTypeID( "wholeWord" );

            desc23.putBoolean( idwholeWord, false );

            var idignoreAccents = stringIDToTypeID( "ignoreAccents" );

            desc23.putBoolean( idignoreAccents, true );

        var idfindReplace = stringIDToTypeID( "findReplace" );

        desc22.putObject( idUsng, idfindReplace, desc23 );

    executeAction( idreplace, desc22, DialogModes.NO );

    }

    catch (e) {}

    };

    3 replies

    D.A.R
    Braniac
    September 12, 2018

    Unfortunately Photoshop is not sophisticated enough to make this change.

    While there is a Find and Replace option in the Edit menu there is no means of entering a Return as the replaced item. You would need to employ a text editor, run the replacement there and then paste the text back to photoshop.

    That would eliminate the possibility of full Action within Photoshop.

    Known Participant
    September 12, 2018

    Thanks. Bummer...

    JJMack
    Braniac
    September 12, 2018

    I do not know what you nean with "what symbol" ???

    It could only be automated with a Photoshop script and it would not be an easy script to code.

    Filter the layers palette  to show only text layers and edit the ones that need editing manually.

    JJMack
    Known Participant
    September 12, 2018

    Like a special character. For instance, in text editors a ^p will insert a new paragraph.

    So I want to know if Photoshop can do this or not.

    Manually change won't work. Too many files.

    Thanks!

    c.pfaffenbichler
    Braniac
    September 13, 2018

    A script should suffice.

    // replace text elements in type layers;

    // 2017, use it at your own risk;

    #target photoshop

    if (app.documents.length > 0) {

    for (var n = 0; n < app.documents.length; n++) {

    app.activeDocument = app.documents;

    app.activeDocument.suspendHistory("replace text", "main()")

    }

    };

    // the opertation;

    function main () {

    var myDocument = app.activeDocument;

    var theArray = [["b", "\r"]];

    for (var b = 0; b < theArray.length; b++) {

    replaceText (theArray[0], theArray[1])

    }

    };

    ////// reoplace text //////

    function replaceText (replaceThis, replaceWith) {

    try {

    // =======================================================

    var idreplace = stringIDToTypeID( "replace" );

        var desc22 = new ActionDescriptor();

        var idnull = charIDToTypeID( "null" );

            var ref3 = new ActionReference();

            var idPrpr = charIDToTypeID( "Prpr" );

            var idreplace = stringIDToTypeID( "replace" );

            ref3.putProperty( idPrpr, idreplace );

            var idTxLr = charIDToTypeID( "TxLr" );

            var idOrdn = charIDToTypeID( "Ordn" );

            var idAl = charIDToTypeID( "Al  " );

            ref3.putEnumerated( idTxLr, idOrdn, idAl );

        desc22.putReference( idnull, ref3 );

        var idUsng = charIDToTypeID( "Usng" );

            var desc23 = new ActionDescriptor();

            var idfind = stringIDToTypeID( "find" );

            desc23.putString( idfind, replaceThis );

            var idreplace = stringIDToTypeID( "replace" );

            desc23.putString( idreplace, replaceWith );

            var idcheckAll = stringIDToTypeID( "checkAll" );

            desc23.putBoolean( idcheckAll, true );

            var idFwd = charIDToTypeID( "Fwd " );

            desc23.putBoolean( idFwd, true );

            var idcaseSensitive = stringIDToTypeID( "caseSensitive" );

            desc23.putBoolean( idcaseSensitive, false );

            var idwholeWord = stringIDToTypeID( "wholeWord" );

            desc23.putBoolean( idwholeWord, false );

            var idignoreAccents = stringIDToTypeID( "ignoreAccents" );

            desc23.putBoolean( idignoreAccents, true );

        var idfindReplace = stringIDToTypeID( "findReplace" );

        desc22.putObject( idUsng, idfindReplace, desc23 );

    executeAction( idreplace, desc22, DialogModes.NO );

    } catch (e) {}

    };

    c.pfaffenbichler
    Braniac
    September 12, 2018

    Have you tried Edit > Find and Replace Text yet?

    Known Participant
    September 12, 2018

    Thanks. Yes. That is what I am doing, but, it won't replace with a carriage return. I don't know if there is a special character that will force a carriage return for the "replace" field.

    JJMack
    Braniac
    September 12, 2018

    You may need to enter them as ascii code using  the alt+numeric keypad in find and replace and you may be able to record that into an action than batch the action.   I have never tried to find a special character like CR LF tab etc

    JJMack