Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Align Active Layer to Canvas.jsx
// Align Active Layer to Canvas.jsx
/*
ADSLefts = Align Left
ADSRights = Align Right
ADSCentersH = Align Centre Horizontal
ADSTops = Align Top
ADSBottoms = Align Bottom
ADSCentersV = Align Centre Vertical
null = insert "null" to quickly disable one of the two alignment options
*/
alignToCanvas(true, "ADSLefts");
alignToCanvas(true, "ADSTops");
function alignToCanvas(alignToCanvas, alignValue) {
app.activeDocument.selection.selectAll();
var s2t = function (s) {
return app.stringIDToTypeID(s);
};
var descriptor = new ActionDescriptor();
var reference = new ActionReference();
reference.putEnumerated( s2t( "layer" ), s2t( "ordinal" ), s2t( "targetEnum" ));
descriptor.putReference( s2t( "null" ), reference );
descriptor.putEnumerated( s2t( "using" ), s2t( "alignDistributeSelector" ), s2t( alignValue ));
descriptor.putBoolean( s2t( "alignToCanvas" ), alignToCanvas );
executeAction( s2t( "align" ), descriptor, DialogModes.NO );
app.activeDocument.selection.deselect();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment