Thank you very much for this script. But, it won't work if I don't select the text layers first.
Btw, I'm really interested in these, where can I find tutorials on photoshop scripts?
Did you try the Script @Davide_Barranca12040269 posted?
Edit: An ESTK-code-version:
// 2024, use it at your own risk;
if (app.documents.length > 0) {
replaceLetterInTypeLayers ("x", "8");
};
////////////////////////////////////
function replaceLetterInTypeLayers (searchText, replaceWith) {
// get number of layers;
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
var applicationDesc = executeActionGet(ref);
var theNumber = applicationDesc.getInteger(stringIDToTypeID("numberOfLayers"));
// process the layers;
var theLayers = new Array;
for (var m = 0; m <= theNumber; m++) {
try {
var ref = new ActionReference();
ref.putIndex( charIDToTypeID( "Lyr " ), m);
var layerDesc = executeActionGet(ref);
var layerSet = typeIDToStringID(layerDesc.getEnumerationValue(stringIDToTypeID("layerSection")));
var isBackground = layerDesc.getBoolean(stringIDToTypeID("background"));
// if not layer group collect values;
if (layerSet != "layerSectionEnd" && layerSet != "layerSectionStart" && isBackground != true && layerDesc.hasKey(stringIDToTypeID("textKey")) == true) {
var theName = layerDesc.getString(stringIDToTypeID('name'));
var theID = layerDesc.getInteger(stringIDToTypeID('layerID'));
try {
var actionDes1 = new ActionDescriptor();
var actionRef = new ActionReference();
selectLayerByID(theID, false);
actionRef.putProperty( charIDToTypeID( "Prpr" ), stringIDToTypeID("replace") );
actionRef.putEnumerated( charIDToTypeID( "TxLr" ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ) );
actionDes1.putReference( charIDToTypeID( "null" ), actionRef );
var actionDes2 = new ActionDescriptor();
actionDes2.putString( stringIDToTypeID( "find" ), searchText );
actionDes2.putString( stringIDToTypeID("replace"), replaceWith );
actionDes2.putBoolean( stringIDToTypeID( "checkAll" ), false );
actionDes2.putBoolean( charIDToTypeID( "Fwd " ), true );
actionDes2.putBoolean( stringIDToTypeID( "caseSensitive" ), false );
actionDes2.putBoolean( stringIDToTypeID( "wholeWord" ), false );
actionDes2.putBoolean( stringIDToTypeID( "ignoreAccents" ), true );
actionDes1.putObject( charIDToTypeID( "Usng" ), stringIDToTypeID( "findReplace" ), actionDes2 );
executeAction( stringIDToTypeID("replace"), actionDes1, DialogModes.NO );
theLayers.push([theName, theID])
} catch (e) {};
};
}
catch (e) {};
};
return theLayers
};
////////////////////////////////////
// based on code by mike hale, via paul riggott;
function selectLayerByID(id,add){
add = undefined ? add = false:add
var ref = new ActionReference();
ref.putIdentifier(charIDToTypeID("Lyr "), id);
var desc = new ActionDescriptor();
desc.putReference(charIDToTypeID("null"), ref );
if(add) desc.putEnumerated( stringIDToTypeID( "selectionModifier" ), stringIDToTypeID( "selectionModifierType" ), stringIDToTypeID( "addToSelection" ) );
desc.putBoolean( charIDToTypeID( "MkVs" ), false );
try{
executeAction(charIDToTypeID("slct"), desc, DialogModes.NO );
}catch(e){
alert(e.message);
}
};