├── README.md └── Align Layers.sketchplugin └── Contents └── Sketch ├── script.js └── manifest.json /README.md: -------------------------------------------------------------------------------- 1 | # Align Layers 2 | Add a keyboard shortcut to the "Align layers" functions in 3 | Sketch. 4 | 5 | - Use `⌘^[` to align layers by their left edges 6 | - Use `⌘^]` to align layers by their horizontal centers 7 | - Use `⌘^\` to align layers by their right edges 8 | - Use `⌘^⇧[` to align layers by their top edges 9 | - Use `⌘^⇧]` to align layers by their vertical centers 10 | - Use `⌘^⇧\` to align layers by their bottom edges 11 | 12 | ## Installation 13 | 1. [Download the plugin repository](https://github.com/daneden/sketch-align-layers/archive/master.zip) 14 | 2. Double-click the `.sketchplugin` file 15 | 3. In Sketch, run the plugin with one of the shortcuts. 16 | -------------------------------------------------------------------------------- /Align Layers.sketchplugin/Contents/Sketch/script.js: -------------------------------------------------------------------------------- 1 | var align = { 2 | Left: "MSAlignLayersLeftAction", 3 | Center: "MSAlignLayersCenterAction", 4 | Right: "MSAlignLayersRightAction", 5 | Top: "MSAlignLayersTopAction", 6 | Middle: "MSAlignLayersMiddleAction", 7 | Bottom: "MSAlignLayersBottomAction" 8 | }; 9 | 10 | function alignLayers(context, alignment) { 11 | var doc = context.document 12 | var action = doc.actionsController().actionForID(alignment); 13 | 14 | if(action.validate()) { 15 | action.doPerformAction(null); 16 | } 17 | } 18 | 19 | // Horizontal alignment 20 | function alignLeft(context) { 21 | alignLayers(context, align.Left); 22 | } 23 | 24 | function alignCenter(context) { 25 | alignLayers(context, align.Center); 26 | } 27 | 28 | function alignRight(context) { 29 | alignLayers(context, align.Right); 30 | } 31 | 32 | // Vertical alignment 33 | function alignTop(context) { 34 | alignLayers(context, align.Top); 35 | } 36 | 37 | function alignMiddle(context) { 38 | alignLayers(context, align.Middle); 39 | } 40 | 41 | function alignBottom(context) { 42 | alignLayers(context, align.Bottom); 43 | } 44 | 45 | -------------------------------------------------------------------------------- /Align Layers.sketchplugin/Contents/Sketch/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "author" : "Daniel Eden", 3 | "commands" : [ 4 | { 5 | "script" : "script.js", 6 | "name" : "Left", 7 | "shortcut" : "cmd ctrl [", 8 | "handlers" : { 9 | "run" : "alignLeft" 10 | }, 11 | "identifier" : "alignLayersLeft" 12 | }, 13 | { 14 | "script" : "script.js", 15 | "name" : "Horizontally", 16 | "shortcut" : "cmd ctrl ]", 17 | "handlers" : { 18 | "run" : "alignCenter" 19 | }, 20 | "identifier" : "alignLayersHorizontally" 21 | }, 22 | { 23 | "script" : "script.js", 24 | "name" : "Right", 25 | "shortcut" : "cmd ctrl \\", 26 | "handlers" : { 27 | "run" : "alignRight" 28 | }, 29 | "identifier" : "alignLayersRight" 30 | }, 31 | 32 | { 33 | "script" : "script.js", 34 | "name" : "Top", 35 | "shortcut" : "cmd ctrl shift [", 36 | "handlers" : { 37 | "run" : "alignTop" 38 | }, 39 | "identifier" : "alignLayersTop" 40 | }, 41 | { 42 | "script" : "script.js", 43 | "name" : "Vertically", 44 | "shortcut" : "cmd ctrl shift ]", 45 | "handlers" : { 46 | "run" : "alignMiddle" 47 | }, 48 | "identifier" : "alignLayersVertically" 49 | }, 50 | { 51 | "script" : "script.js", 52 | "name" : "Bottom", 53 | "shortcut" : "cmd ctrl shift \\", 54 | "handlers" : { 55 | "run" : "alignBottom" 56 | }, 57 | "identifier" : "alignLayersBottom" 58 | } 59 | ], 60 | "menu" : { 61 | "items" : [ 62 | "alignLayersLeft", 63 | "alignLayersHorizontally", 64 | "alignLayersRight", 65 | "-", 66 | "alignLayersTop", 67 | "alignLayersVertically", 68 | "alignLayersBottom" 69 | ], 70 | "title" : "Align Layers" 71 | }, 72 | "identifier" : "me.daneden.SketchAlignLayers", 73 | "version" : "1.2", 74 | "description" : "Add shortcuts to the 'align layers' actions", 75 | "authorEmail" : "dan.eden@me.com", 76 | "name" : "Align Layers" 77 | } 78 | --------------------------------------------------------------------------------