Skip to content

Instantly share code, notes, and snippets.

Last active June 22, 2022 12:58
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
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) {
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 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment