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
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
Copy link to clipboard
Copied
Have you tried Edit > Find and Replace Text yet?
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.
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
Copy link to clipboard
Copied
Thanks! I'll look into it!
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.
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!
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) {}
};
Copy link to clipboard
Copied
Good show....
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) {}
};
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!!!
Copy link to clipboard
Copied
Change line 21 if you want to find and replace delete the "afterText +"
var theArray = [[ afterText , afterText + "\r"]];
Copy link to clipboard
Copied
Thank you so much JJMack​. That's Perfect!
Copy link to clipboard
Copied
You thanking the wrong user its c.pfaffenbichler script I just tweaked it for you.
Copy link to clipboard
Copied
AWESOME! Thanks! WOW~
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.
Copy link to clipboard
Copied
Thanks. Bummer...
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
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?
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.
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?
Copy link to clipboard
Copied
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.