Find Text and Replace with Carriage Return
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
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
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) {}
};
Already have an account? Login
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.