Copy link to clipboard
Copied
Hi there,
Let us say I have six Photoshop files: 1.psd, 2.psd, ..., 6.psd. All of these files contain the word “LoremIpsum” in random text layers, within each document. Is there a way I can search for “LoremIpsum” in all documents and replace it with “Dolor Sit Amet”, all in one go? This is just an example, I need to replace various words, not just one.
I have tried "batch find and replace" software (including powerful tools like Power Grep) but they do not work with psd files… Is there a javascript of external plugin for this kind of task?
Thanks!
Copy link to clipboard
Copied
i have the same proplem with you . But now after i tried reinstall PTS cs6 , ít can't be open . Please help me !
Copy link to clipboard
Copied
Chisaicoi let us know what error you receive so I (and most likely more experienced members) can help...
In the meantime, no progress for me, still stuck...
Copy link to clipboard
Copied
This should work on all open documents if the Type Layers’ content is uniform.
// replace text elements in type layers;
// 2013, 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 theLayers = collectTextLayers(myDocument, []);
if (theLayers.length > 0) {
var theArray1 = ["LoremIpsum"];
var theArray2 = ["Dolor Sit Amet"];
for (var a = 0; a < theLayers.length; a++) {
for (var b = 0; b < theArray1.length; b++) {
var theString = theLayers.textItem.contents;
while (theString.indexOf(theArray1) != -1) {
theString = theString.replace(theArray1, theArray2)
};
theLayers.textItem.contents = theString;
}
}
}
};
////// function collect all layers //////
function collectTextLayers (theParent, allLayers) {
if (!allLayers) {var allLayers = new Array};
else {};
for (var m = theParent.layers.length - 1; m >= 0;m--) {
var theLayer = theParent.layers
; // apply the function to layersets;
if (theLayer.typename == "ArtLayer") {
if (theLayer.kind == LayerKind.TEXT) {allLayers.push(theLayer)};
}
else {
allLayers = (collectTextLayers(theLayer, allLayers))
// this line includes the layer groups;
// allLayers.push(theLayer);
}
};
return allLayers
};
Copy link to clipboard
Copied
I have 2 different words sets, this script is for single combination, can u plz modify... thanks in advance
Copy link to clipboard
Copied
// 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 = [["TEST", "123"], ["HAHAHA", "456"]];
for (var b = 0; b < theArray.length; b++) {
replaceText (theArray[0], theArray[1])
}
};
////// reoplace text //////
function replaceText (replaceThis, replaceWith) {
// =======================================================
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 );
};
Copy link to clipboard
Copied
thanks its working, but it dosent work in photoshop cc 2017 but it works on cs6,
Copy link to clipboard
Copied
Start a new thread if you need help.
Copy link to clipboard
Copied
it shows this error, need help
Copy link to clipboard
Copied
So start a new thread.
Error: And provide more details about the file on which the error occurs.
Copy link to clipboard
Copied
Or wrap the code in the replaceText-function in a try-clause.
Copy link to clipboard
Copied
?
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Hey there, I am looking to do the same thing within photoshop cc19 and was wondering if you started a new thread to help deal with your error or if you found a solution to this problem? I am also getting similar errors when I try to run this in cc19.
Cheers,
Marty
Copy link to clipboard
Copied
Please start a new thread so we can figure out what you need.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now