├── MoveIt.sketchplugin └── Contents │ └── Sketch │ ├── manifest.json │ └── script.cocoascript ├── README.md └── images ├── moveit.png ├── problem.gif └── solution.gif /MoveIt.sketchplugin/Contents/Sketch/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "name" : "MoveIt", 3 | "author" : "Dawid Woźniak", 4 | "description" : "Let's you move selected layers verticaly and horizontaly.", 5 | "authorEmail" : "dawid@plaind.pl", 6 | "version" : "1.0", 7 | "commands" : [ 8 | { 9 | "script" : "script.cocoascript", 10 | "handler" : "onRun", 11 | "shortcut" : "cmd shift m", 12 | "name" : "MoveIt", 13 | "identifier" : "moveit" 14 | } 15 | ], 16 | "menu" : { 17 | "items" : [ 18 | "moveit" 19 | ], 20 | "title" : "MoveIt" 21 | }, 22 | "identifier" : "com.example.sketch.5e5693a0-fcd9-4b54-990d-649a41482f79" 23 | } 24 | -------------------------------------------------------------------------------- /MoveIt.sketchplugin/Contents/Sketch/script.cocoascript: -------------------------------------------------------------------------------- 1 | var onRun = function(context) { 2 | var selection = context.selection 3 | 4 | if (selection.length > 0){ 5 | 6 | var alert = buildDialog(selection.length) 7 | var options = handleAlertResponse(alert, alert.runModal()); 8 | var loop = selection.objectEnumerator() 9 | 10 | while (item = loop.nextObject()) { 11 | item.frame().setX(parseFloat(item.frame().x()) + parseFloat(options['new_x'])); 12 | item.frame().setY(parseFloat(item.frame().y()) + parseFloat(options['new_y'])); 13 | } 14 | 15 | } else { 16 | context.document.showMessage("Yo, select some layers") 17 | } 18 | 19 | function evaluate(value) { 20 | value = eval(value.replace(/[^\d\-\*\.\+\/\(\)]/g, '')); 21 | return value ? value : 0; 22 | } 23 | 24 | function handleAlertResponse(alert, responseCode) { 25 | if (responseCode == "1000") { 26 | function valAtIndex (view, index) { 27 | return parseInt(evaluate(view.viewAtIndex(index).stringValue())); 28 | } 29 | 30 | return { 31 | new_x: evaluate(alert.viewAtIndex(1).stringValue()), 32 | new_y: evaluate(alert.viewAtIndex(3).stringValue()) 33 | } 34 | } 35 | 36 | return null; 37 | } 38 | 39 | function buildDialog(count){ 40 | var alert = COSAlertWindow.new(); 41 | 42 | function addFieldWithLabel(label,defaultValue) { 43 | alert.addTextLabelWithValue(label); 44 | alert.addTextFieldWithValue(defaultValue); 45 | } 46 | 47 | if (count > 1) { var lay = 'layers' } else { var lay = 'layer'} 48 | alert.setMessageText("Move " + count + " " + lay); 49 | 50 | addFieldWithLabel("Move horizontally, px",""); 51 | addFieldWithLabel("Move vertically, px",""); 52 | 53 | alert.addButtonWithTitle('OK'); 54 | alert.addButtonWithTitle('Cancel'); 55 | 56 | var firstField = alert.viewAtIndex(1); 57 | var secondField = alert.viewAtIndex(3); 58 | alert.alert().window().setInitialFirstResponder(firstField); 59 | firstField.setNextKeyView(secondField); 60 | secondField.setNextKeyView(firstField); 61 | 62 | return alert; 63 | } 64 | }; 65 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Move It 2 | Sketch plugin that let's you move selected layers vertically and horizontally. 3 | Because there wasn't Illustrator Move feature out of the box. 4 | 5 | ![Move it screen](./images/solution.gif) 6 | 7 | Thanks to [Vlad Moroz](https://github.com/vladmoroz) you can now use math operators in inputs: 8 | ``` 9 | X: 10*12+30-5 will move layer by 145 pixels 10 | Y: 1/3 will move layer by 0.33(3) pixels 11 | ``` 12 | 13 | Supported operators: + - * / ( ) 14 | 15 | ## Installation 16 | 1. Download plugin 17 | 2. Navigate the Sketch menu bar to `Plugins ▸ Reveal Plugins Folder...` 18 | 3. Place the `MoveIt` folder into the revealed plugins directory 19 | 4. That's it... 20 | 21 | ## Usage 22 | 1. Select layer(s) you want to move. 23 | 2. `Plugins ▸ Move It ▸ MoveIt` or cmd + shift + m 24 | 3. Enter how many px you want to move layer(s) horizontally and vertically. 25 | 4. Click OK. 26 | 27 | ## Contributors 28 | * Vlad Moroz (https://twitter.com/vladyslavmoroz) - fixed autofocus on input in new Sketch version, added math expressions handling 29 | 30 | ## Contact 31 | * Follow [@dawidwu](http://twitter.com/dawidwu) on Twitter 32 | * Email 33 | -------------------------------------------------------------------------------- /images/moveit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dawidw/move-it/63f7457ac63f86ff04a73343123dae14792febd7/images/moveit.png -------------------------------------------------------------------------------- /images/problem.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dawidw/move-it/63f7457ac63f86ff04a73343123dae14792febd7/images/problem.gif -------------------------------------------------------------------------------- /images/solution.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dawidw/move-it/63f7457ac63f86ff04a73343123dae14792febd7/images/solution.gif --------------------------------------------------------------------------------