Please use complete and meaningful sentences to describe your intentions.
Copy/pasting and even dragging/dropping Layers seem unnecessary if the images are existing jpgs – simply placing them as Smart Objects would seem more efficient in this case.
code edited
// placeOpenImagesOnShapeLayers;
// 2023, use it at your own risk;
//#target photoshop
if (app.documents.length > 0) {
var originalRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.POINTS;
var myDocument = app.activeDocument;
var theShapes = collectShapeLayersBounds();
var theDocuments = new Array;
if (theShapes.length > 0) {
// the other documents;
for (var m = 0; m < app.documents.length; m++) {
if (app.documents[m] != myDocument) {theDocuments.push(app.documents[m])}
};
// place images;
var theId = 0;
for (var n = 0; n < theDocuments.length; n++) {
selectLayerByID(theShapes[theId][1], false);
placeScaleRotateFile (theDocuments[n].fullName, 0, 0, 100, 100, 0);
scaleToBounds (theShapes[theId][2]);
myDocument.activeLayer.grouped = true;
if (theId == theShapes.length-1) {theId = 0} else {theId++};
};
} else {alert ("no shape layers")};
app.preferences.rulerUnits = originalRulerUnits;
};
////////////////////////////////////
////// place //////
function placeScaleRotateFile (file, xOffset, yOffset, theXScale, theYScale, theAngle) {
// =======================================================
var desc5 = new ActionDescriptor();
desc5.putPath( charIDToTypeID( "null" ), new File( file ) );
desc5.putEnumerated( charIDToTypeID( "FTcs" ), idQCSt = charIDToTypeID( "QCSt" ), charIDToTypeID( "Qcsa" ) );
var idOfst = charIDToTypeID( "Ofst" );
var desc6 = new ActionDescriptor();
var idPxl = charIDToTypeID( "#Pxl" );
desc6.putUnitDouble( charIDToTypeID( "Hrzn" ), idPxl, xOffset );
desc6.putUnitDouble( charIDToTypeID( "Vrtc" ), idPxl, yOffset );
var idOfst = charIDToTypeID( "Ofst" );
desc5.putObject( idOfst, idOfst, desc6 );
var idPrc = charIDToTypeID( "#Prc" );
desc5.putUnitDouble( charIDToTypeID( "Wdth" ), idPrc, theYScale );
desc5.putUnitDouble( charIDToTypeID( "Hght" ), idPrc, theXScale );
desc5.putUnitDouble( charIDToTypeID( "Angl" ), charIDToTypeID( "#Ang" ),theAngle );
desc5.putBoolean( charIDToTypeID( "Lnkd" ), false );
executeAction( charIDToTypeID( "Plc " ), desc5, DialogModes.NO );
return app.activeDocument.activeLayer;
};
////// scale active layer to bounds //////
function scaleToBounds (targetBounds) {
// scale smart object:
var originalRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.POINTS;
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
var layerDesc = executeActionGet(ref);
var theBounds = layerDesc.getObjectValue(stringIDToTypeID('bounds'));
var theX = theBounds.getInteger(stringIDToTypeID('left'));
var theY = theBounds.getInteger(stringIDToTypeID('top'));
var theX2 = theBounds.getInteger(stringIDToTypeID('right'));
var theY2 = theBounds.getInteger(stringIDToTypeID('bottom'));
// determine the scale;
var boundsWidth = targetBounds[2]-targetBounds[0];
var boundsHeight = targetBounds[3]-targetBounds[1];
var theSOProp = boundsWidth/boundsHeight;
var theNewProp = (theX2 - theX)/(theY2 - theY);
if (theNewProp <= theSOProp) {var theScale = boundsWidth / (theX2 - theX) * 100}
else {var theScale = boundsHeight / (theY2 - theY) * 100};
// transform;
var desc23 = new ActionDescriptor();
var ref2 = new ActionReference();
ref2.putEnumerated( charIDToTypeID( "Lyr " ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ) );
desc23.putReference( charIDToTypeID( "null" ), ref2 );
var idOfst = charIDToTypeID( "Ofst" );
var desc24 = new ActionDescriptor();
var idPxl = charIDToTypeID( "#Pxl" );
desc24.putUnitDouble( charIDToTypeID( "Hrzn" ), idPxl, targetBounds[0]+boundsWidth/2 - (theX+(theX2-theX)/2) );
desc24.putUnitDouble( charIDToTypeID( "Vrtc" ), idPxl, targetBounds[1]+boundsHeight/2 - (theY+(theY2-theY)/2) );
desc23.putObject( idOfst, idOfst, desc24 );
var idPrc = charIDToTypeID( "#Prc" );
desc23.putUnitDouble( charIDToTypeID( "Wdth" ), idPrc, theScale );
desc23.putUnitDouble( charIDToTypeID( "Hght" ), idPrc, theScale );
desc23.putEnumerated( charIDToTypeID( "Intr" ), charIDToTypeID( "Intp" ), stringIDToTypeID( "bicubicAutomatic" ) );
desc23.putEnumerated( stringIDToTypeID( "freeTransformCenterState" ), stringIDToTypeID( "quadCenterState" ), stringIDToTypeID( "QCSAverage" ) );
executeAction( charIDToTypeID( "Trnf" ), desc23, DialogModes.NO );
app.preferences.rulerUnits = originalRulerUnits;
};
////// collect shape layer bounds //////
function collectShapeLayersBounds () {
// 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) {
var theName = layerDesc.getString(stringIDToTypeID('name'));
var theID = layerDesc.getInteger(stringIDToTypeID('layerID'));
var theKind = layerDesc.getInteger(stringIDToTypeID('layerKind'));
if (theKind == 4) {
var theBounds = layerDesc.getObjectValue(stringIDToTypeID("bounds"));
var theseBounds = [theBounds.getUnitDoubleValue(stringIDToTypeID("left")), theBounds.getUnitDoubleValue(stringIDToTypeID("top")), theBounds.getUnitDoubleValue(stringIDToTypeID("right")), theBounds.getUnitDoubleValue(stringIDToTypeID("bottom"))];
theLayers.push([theName, theID, theseBounds])
}
};
}
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);
}
};
If the goal is to set up four rectangles as placeholders, draw them using the Frame tool. When they are frames, they are placeholders for future graphics, so all you have to do is select a frame and paste an image you copied from another document. It pastes inside the frame.