Edit: To be more thorough one should include a check for applied transformations/warps.
// 2026, use it at your own risk;
if (app.documents.length > 0) {
var originalRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
var myDocument = activeDocument;
var theRes = 72*myDocument.resolution;
// ger values;
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
var layerDesc = executeActionGet(ref);
var soDesc = layerDesc.getObjectValue(stringIDToTypeID('smartObject'));
var soMoreDesc = layerDesc.getObjectValue(stringIDToTypeID('smartObjectMore'));
var transform = soMoreDesc.getList(stringIDToTypeID("transform"));
var xx = new Array;
for (var m = 0; m < transform.count; m++) {
xx.push(transform.getDouble(m))
};
// open and crop:
var theSO = openSmartObject();
theSO.crop([xx[0]*(-1), xx[1]*(-1), xx[0]*(-1)+myDocument.width, xx[1]*(-1)+myDocument.height]);
theSO.close(SaveOptions.SAVECHANGES);
// align layer;
var thisOne = myDocument.activeLayer;
thisOne.translate(thisOne.bounds[0]*(-1), thisOne.bounds[1]*(-1));
// reset;
app.preferences.rulerUnits = originalRulerUnits;
};
////////////////////////////////////
////// open the smart object //////
function openSmartObject () {
try {
var desc3 = new ActionDescriptor();
executeAction( stringIDToTypeID( "placedLayerEditContents" ), desc3, DialogModes.NO );
return app.activeDocument
} catch (e) {alert (e)};
};
... View more