Skip to content

Instantly share code, notes, and snippets.

@MarshySwamp
Last active June 22, 2022 12:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MarshySwamp/618a08fd04c4f3ed0027f6926b6d9d62 to your computer and use it in GitHub Desktop.
Save MarshySwamp/618a08fd04c4f3ed0027f6926b6d9d62 to your computer and use it in GitHub Desktop.
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