

// place "_shadow.png" in png and save psd;
// 2025, use it at your own risk;
var theFolder = Folder.selectDialog ("select folder");
if (theFolder) {
// psd options;
saveOpts = new PhotoshopSaveOptions();
saveOpts.embedColorProfile = true;
saveOpts.alphaChannels = false;
saveOpts.layers = true;
saveOpts.spotColors = true;
var theRegExp =/_shadow.png/i;
var theFiles = theFolder.getFiles(/\.(png)$/i)
for (var m = 0; m < theFiles.length; m++) {
var thisOne = theFiles[m];
if (String(thisOne).match(theRegExp) == null) {
var theShadow = String(thisOne).replace(/_*.png/, "_shadow.png");
if (File(theShadow).exists == true) {
var myImage = app.open(thisOne);
placeScaleRotateFile(theShadow, 0, 0, 100, 100, 0, false);
rasterizeSmartObject ();
moveLayerDown();
myImage.saveAs(new File(String(thisOne).replace(".png", ".psd")), saveOpts, true);
myImage.close(SaveOptions.DONOTSAVECHANGES)
}
}
}
};
////// place //////
function placeScaleRotateFile (file, xOffset, yOffset, theXScale, theYScale, theAngle, linked) {
var idPxl = charIDToTypeID( "#Pxl" );
var idPrc = charIDToTypeID( "#Prc" );
var idPlc = charIDToTypeID( "Plc " );
var desc5 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
desc5.putPath( idnull, new File( file ) );
var idFTcs = charIDToTypeID( "FTcs" );
var idQCSt = charIDToTypeID( "QCSt" );
var idQcsa = charIDToTypeID( "Qcsa" );
desc5.putEnumerated( idFTcs, idQCSt, idQcsa );
var idOfst = charIDToTypeID( "Ofst" );
var desc6 = new ActionDescriptor();
var idHrzn = charIDToTypeID( "Hrzn" );
desc6.putUnitDouble( idHrzn, idPxl, xOffset );
var idVrtc = charIDToTypeID( "Vrtc" );
desc6.putUnitDouble( idVrtc, idPxl, yOffset );
var idOfst = charIDToTypeID( "Ofst" );
desc5.putObject( idOfst, idOfst, desc6 );
var idWdth = charIDToTypeID( "Wdth" );
desc5.putUnitDouble( idWdth, idPrc, theYScale );
var idHght = charIDToTypeID( "Hght" );
desc5.putUnitDouble( idHght, idPrc, theXScale );
var idAngl = charIDToTypeID( "Angl" );
var idAng = charIDToTypeID( "#Ang" );
desc5.putUnitDouble( idAngl, idAng,theAngle );
if (linked == true) {
var idLnkd = charIDToTypeID( "Lnkd" );
desc5.putBoolean( idLnkd, true );
};
executeAction( idPlc, desc5, DialogModes.NO );
// get layerid;
var ref = new ActionReference();
ref.putProperty (stringIDToTypeID ("property"), stringIDToTypeID ("layerID"));
ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
var layerDesc = executeActionGet(ref);
var layerID = layerDesc.getInteger (stringIDToTypeID ("layerID"));
return layerID;
};
////// move layer down //////
function moveLayerDown () {
var desc5 = new ActionDescriptor();
var ref3 = new ActionReference();
ref3.putEnumerated( charIDToTypeID( "Lyr " ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ) );
desc5.putReference( charIDToTypeID( "null" ), ref3 );
var ref4 = new ActionReference();
ref4.putEnumerated( charIDToTypeID( "Lyr " ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Prvs" ) );
desc5.putReference( charIDToTypeID( "T " ), ref4 );
executeAction( charIDToTypeID( "move" ), desc5, DialogModes.NO );
};
////// rasterize the so //////
function rasterizeSmartObject () {
try {
var desc125 = new ActionDescriptor();
var ref83 = new ActionReference();
ref83.putEnumerated( charIDToTypeID( "Mn " ), charIDToTypeID( "MnIt" ), stringIDToTypeID( "rasterizePlaced" ) );
desc125.putReference( charIDToTypeID( "null" ), ref83 );
executeAction( charIDToTypeID( "slct" ), desc125, DialogModes.NO );
} catch (e) {}
};
edited 2025-01-26