• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Find Text and Replace with Carriage Return

Explorer ,
Sep 12, 2018 Sep 12, 2018

Copy link to clipboard

Copied

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

Views

3.6K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Sep 13, 2018 Sep 13, 2018

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

...

Votes

Translate

Translate
Adobe
Community Expert ,
Sep 12, 2018 Sep 12, 2018

Copy link to clipboard

Copied

Have you tried Edit > Find and Replace Text yet?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 12, 2018 Sep 12, 2018

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 12, 2018 Sep 12, 2018

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 12, 2018 Sep 12, 2018

Copy link to clipboard

Copied

Thanks! I'll look into it!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 12, 2018 Sep 12, 2018

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 12, 2018 Sep 12, 2018

Copy link to clipboard

Copied

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!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 12, 2018 Sep 12, 2018

Copy link to clipboard

Copied

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

};

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 13, 2018 Sep 13, 2018

Copy link to clipboard

Copied

Good show....

JJMack

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 13, 2018 Sep 13, 2018

Copy link to clipboard

Copied

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

};

JJMack

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 13, 2018 Sep 13, 2018

Copy link to clipboard

Copied

Wow!  This is perfect!  Works almost exactly.

It puts in the return perfect.

Is there a way to delete the text that is entered?

For example,

This is the  full text = My MomPPPGloria SmithPPPIs the Best

So the text to search for = PPP

The final result will look like

My Mom

Gloria Smith

Is the Best

THANK YOU SO MUCH!!!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 14, 2018 Sep 14, 2018

Copy link to clipboard

Copied

Change line 21 if you want to find and replace delete the "afterText  +"

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

JJMack

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 14, 2018 Sep 14, 2018

Copy link to clipboard

Copied

Thank you so much JJMack​. That's Perfect!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 14, 2018 Sep 14, 2018

Copy link to clipboard

Copied

You thanking the wrong user its c.pfaffenbichler script I just tweaked it for you.

JJMack

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 13, 2018 Sep 13, 2018

Copy link to clipboard

Copied

AWESOME! Thanks! WOW~

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Sep 12, 2018 Sep 12, 2018

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 12, 2018 Sep 12, 2018

Copy link to clipboard

Copied

Thanks. Bummer...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 14, 2018 Sep 14, 2018

Copy link to clipboard

Copied

c.pfaffenbichler found using Action manager code that JavaScript excape sequence can be used in  in Photoshop's find and replace text. Text fields.

JavaScript Escape Sequence Character represented

\0 The NUL character (\u0000)

\b Backspace (\u0008)

\t Horizontal tab (\u0009)

\n Newline (\u000A)

\v Vertical tab (\u000B)

\f Form feed (\u000C)

\r Carriage return (\u000D)

\" Double quote (\u0022)

\' Apostrophe or single quote (\u0027)

\\ Backslash (\u005C)

\x XX The Latin-1 character specified by the two hexadecimal digits XX

\u XXXX The Unicode character specified by the four hexadecimal digits XXXX

JJMack

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Sep 14, 2018 Sep 14, 2018

Copy link to clipboard

Copied

When I looked at your script I did actually try the \r in hopes that would be a solution.

In my test here I used \u000D but it simply changed the text to that. What am I missing?

Screenshot 2018-09-14 12.24.39.png

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 14, 2018 Sep 14, 2018

Copy link to clipboard

Copied

If my script did  not change the text and insert the Carriage returns are you sure the text you entered in the prompt is in your open documents?. You can not use Photoshop's  Find and replace Text  Dialog UI.  The Dialog interface will not interpret JavaScript escape sequences.  You need to use a javascript and use action manager code to bypass the UI Dialog pass the data directly to the command.

Capture.jpg

JJMack

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Sep 15, 2018 Sep 15, 2018

Copy link to clipboard

Copied

I misunderstood. I thought with this statement 'can be used in  in Photoshop's find and replace text. Text fields." You were suggesting that I could indeed use the PS Find and replace dialog.

No matter.

Now, what is Action Manager Code?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 15, 2018 Sep 15, 2018

Copy link to clipboard

Copied

LATEST

Adobe Script DOM does not cover all of Photoshop Features.   Many of Photoshop features can not be scripted using Adobe Script DOM. Action can automate these features.

Adobe also provide a Plug-in namely Scriptlistener.   The Scriptlistiner is like an Action recorder.   However it does not record actions.  The scriptlistener records two log on you desktop.  One is in VSB syntax for Action Steps the other JavaScript for Action Steps.    The code uses Adobe Action Manager to perform Action steps.    Like Action Steps the steps recorded by the Scriptlistiner are Hard coded steps all settings are hard coded.   However the hard coded setting can be change by a JavaScript with logic added added to change the setting used.    So if you record a Find and  replace text step in an action the Find Text and the replace text is recorded into the action step. The step will always use the same text unless you turn on the steps dialog and make it interactive.  Even if you turn on the step dialog the recorded fine text and replace text will show in the dialog however you can interactive change it.

So what you see in the Script is an Action Step that has been made into a script function that  has two parameters which change the find text fields and the replace text fields in the Action step.   The settings that were recorded by the scriptlisener have been replaces with variables these are set in the script and passed to the function the function set these into the Action Step.  It may look ugly but it works.

  1. ////// reoplace text ////// 
  2. function replaceText (replaceThis, replaceWith) { 
  3. try
  4. // ======================================================= 
  5. var idreplace = stringIDToTypeID( "replace" ); 
  6.     var desc22 = new ActionDescriptor(); 
  7.     var idnull = charIDToTypeID( "null" ); 
  8.         var ref3 = new ActionReference(); 
  9.         var idPrpr = charIDToTypeID( "Prpr" ); 
  10.         var idreplace = stringIDToTypeID( "replace" ); 
  11.         ref3.putProperty( idPrpr, idreplace ); 
  12.         var idTxLr = charIDToTypeID( "TxLr" ); 
  13.         var idOrdn = charIDToTypeID( "Ordn" ); 
  14.         var idAl = charIDToTypeID( "Al  " ); 
  15.         ref3.putEnumerated( idTxLr, idOrdn, idAl ); 
  16.     desc22.putReference( idnull, ref3 ); 
  17.     var idUsng = charIDToTypeID( "Usng" ); 
  18.         var desc23 = new ActionDescriptor(); 
  19.         var idfind = stringIDToTypeID( "find" ); 
  20.         desc23.putString( idfind, replaceThis ); 
  21.         var idreplace = stringIDToTypeID( "replace" ); 
  22.         desc23.putString( idreplace, replaceWith ); 
  23.         var idcheckAll = stringIDToTypeID( "checkAll" ); 
  24.         desc23.putBoolean( idcheckAll, true ); 
  25.         var idFwd = charIDToTypeID( "Fwd " ); 
  26.         desc23.putBoolean( idFwd, true ); 
  27.         var idcaseSensitive = stringIDToTypeID( "caseSensitive" ); 
  28.         desc23.putBoolean( idcaseSensitive, false ); 
  29.         var idwholeWord = stringIDToTypeID( "wholeWord" ); 
  30.         desc23.putBoolean( idwholeWord, false ); 
  31.         var idignoreAccents = stringIDToTypeID( "ignoreAccents" ); 
  32.         desc23.putBoolean( idignoreAccents, true ); 
  33.     var idfindReplace = stringIDToTypeID( "findReplace" ); 
  34.     desc22.putObject( idUsng, idfindReplace, desc23 ); 
  35. executeAction( idreplace, desc22, DialogModes.NO ); 
  36. }  
  37. catch (e) {} 
  38. }; 
JJMack

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines