My use case:
- a psd file with a mockup
- frame in the middle to contain an image
- script opens the psd doc
- script locates a jpg file in the file system
- script should add that image to the frame (just because the image can be placed nicely, without the need to adjust size if I were to use a smart object layer instead)
no masking involved
Many things are not covered under the standard JavaScript object model reference, one has to use action manager code. The easiest way to do this is to use the scripting listener plugin and or the clean sl script on the recorded code, however some folk understand how to write it from scratch without this crutch.
Presuming that your existing code is set to open the targetFile.psd and to select the targetLayer that contains the frame:
placeEvent(5, new File( "~/Desktop/sourceFile.jpg" ), true, 0, 0);
function placeEvent(ID, null2, linked, horizontal, vertical) {
var s2t = function (s) {
return app.stringIDToTypeID(s);
};
var descriptor = new ActionDescriptor();
var descriptor2 = new ActionDescriptor();
descriptor.putInteger( s2t( "ID" ), ID );
descriptor.putPath( s2t( "null" ), null2 );
descriptor.putBoolean( s2t( "linked" ), linked ); // change true to false to embedd
descriptor.putEnumerated( s2t( "freeTransformCenterState" ), s2t( "quadCenterState" ), s2t( "QCSAverage" ));
descriptor2.putUnitDouble( s2t( "horizontal" ), s2t( "pixelsUnit" ), horizontal );
descriptor2.putUnitDouble( s2t( "vertical" ), s2t( "pixelsUnit" ), vertical );
descriptor.putObject( s2t( "offset" ), s2t( "offset" ), descriptor2 );
executeAction(s2t( "placeEvent" ), descriptor, DialogModes.NO);
}
The above code presumes a file titled sourceFile.jpg on the desktop.