// 2016, use it at your own risk; #target photoshop if (app.documents.length > 0) { var myDocument = app.activeDocument; var originalRulerUnits = app.preferences.rulerUnits; app.preferences.rulerUnits = Units.PIXELS; var width = myDocument.width; var height = myDocument.height; var rel = 1; if (myDocument.name.indexOf("AB10") != -1) {var rel = 0.666}; if (myDocument.name.indexOf("CD10") != -1) {var rel = 0.75}; if (myDocument.name.indexOf("EF10") != -1) {var rel = 0.8}; if (myDocument.name.indexOf("CH10") != -1) {var rel = 0.833}; try { // ======================================================= var idCrop = charIDToTypeID( "Crop" ); var desc3 = new ActionDescriptor(); var idT = charIDToTypeID( "T " ); var desc4 = new ActionDescriptor(); var idTop = charIDToTypeID( "Top " ); var idPxl = charIDToTypeID( "#Pxl" ); desc4.putUnitDouble( idTop, idPxl, 0 ); var idLeft = charIDToTypeID( "Left" ); var idPxl = charIDToTypeID( "#Pxl" ); desc4.putUnitDouble( idLeft, idPxl, (width - height * rel) / 2 ); var idBtom = charIDToTypeID( "Btom" ); var idPxl = charIDToTypeID( "#Pxl" ); desc4.putUnitDouble( idBtom, idPxl, height ); var idRght = charIDToTypeID( "Rght" ); var idPxl = charIDToTypeID( "#Pxl" ); desc4.putUnitDouble( idRght, idPxl, (width - height * rel) / 2 + height * rel ); var idRctn = charIDToTypeID( "Rctn" ); desc3.putObject( idT, idRctn, desc4 ); var idAngl = charIDToTypeID( "Angl" ); var idAng = charIDToTypeID( "#Ang" ); desc3.putUnitDouble( idAngl, idAng, 0.000000 ); var idDlt = charIDToTypeID( "Dlt " ); desc3.putBoolean( idDlt, false ); var idcropAspectRatioModeKey = stringIDToTypeID( "cropAspectRatioModeKey" ); var idcropAspectRatioModeClass = stringIDToTypeID( "cropAspectRatioModeClass" ); var idpureAspectRatio = stringIDToTypeID( "pureAspectRatio" ); desc3.putEnumerated( idcropAspectRatioModeKey, idcropAspectRatioModeClass, idpureAspectRatio ); var idCnsP = charIDToTypeID( "CnsP" ); desc3.putBoolean( idCnsP, true ); executeAction( idCrop, desc3, DialogModes.ALL ); } catch (e) {}; // app.preferences.rulerUnits = originalRulerUnits; }; |