Copy link to clipboard
Copied
I have the below script which find and replace only only one sentence I want to 2 different sentence should be find and replaced, need modification, thanks in advance
#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 = ["FIND OUT MORE"];
var theArray2 = ["ĎALŠIE INFORMÁCIE"];
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
};
First iff you may want to post over on
and secondly that looks like DOM code and you may get considerably better performance with AM code.
Is there any way of accessing Find and Replace Text... through scripting?
Copy link to clipboard
Copied
First iff you may want to post over on
and secondly that looks like DOM code and you may get considerably better performance with AM code.
Is there any way of accessing Find and Replace Text... through scripting?