diff --git a/RandomColor.sketchplugin/Contents/Sketch/script.cocoascript b/RandomColor.sketchplugin/Contents/Sketch/script.cocoascript index 87f6d94..9674ee2 100644 --- a/RandomColor.sketchplugin/Contents/Sketch/script.cocoascript +++ b/RandomColor.sketchplugin/Contents/Sketch/script.cocoascript @@ -1,3 +1,4 @@ +function onRun(context) { // Define color palette var color1 = "#FC583B" @@ -71,3 +72,4 @@ var lastColor = r } } +} \ No newline at end of file diff --git a/Sketch/manifest.json b/Sketch/manifest.json deleted file mode 100644 index ca8e2c1..0000000 --- a/Sketch/manifest.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "author" : "Avadh Dwivedi", - "commands" : [ - { - "script" : "script.cocoascript", - "name" : "RandomColor", - "handlers" : { - "run" : "onRun" - }, - "identifier" : "com.bohemiancoding.sketch.runscriptidentifier" - } - ], - "menu" : { - "items" : [ - "com.bohemiancoding.sketch.runscriptidentifier" - ], - "title" : "RandomColor" - }, - "identifier" : "com.example.sketch.02bc3584-c0b4-4b1d-9f17-a4bdb4fedbdf", - "version" : "1.0", - "description" : "Apply a color palette to a group of objects", - "authorEmail" : "avadh@ymail.com", - "name" : "RandomColor" -} diff --git a/Sketch/script.cocoascript b/Sketch/script.cocoascript deleted file mode 100644 index 87f6d94..0000000 --- a/Sketch/script.cocoascript +++ /dev/null @@ -1,73 +0,0 @@ -// Define color palette - - var color1 = "#FC583B" - var color2 = "#FFD100" - var color3 = "#3ADCBE" - var color4 = "#5071FF" - var color5 = "#014EEF" - var color6 = "#FFF200" - var color7 = "#78379D" - var color8 = "#FE4F20" - var color9 = "#40BE65" - var color10 = "#EDC054" - var color11 = "#EDC054" - - -//Select a random number - - function getRandomIntInclusive(min, max) { - min = Math.ceil(min); - max = Math.floor(max); - return Math.floor(Math.random() * (max - min)) + min; - } - - -// Define array of previously set colors - - var colors = [color1, color2, color3, color4, color5, color6,color7,color8,color9,color10,color11] - - -// Get the current selection - - var selection = context.selection - - -// Prepare for looping through objects in current selection - - var loop = selection.objectEnumerator() - - -// Loop through object and change its fill color - - while (item = loop.nextObject()) { - - if (item.class() === MSShapeGroup) { - - //Get layer style - var shapeStyle = item.style(); - - //Get layer style fills array - var fills = shapeStyle.fills(); - - //Set fill style if not created - if(fills.count() <= 0){ - fills.addNewStylePart(); - } - - //Get first fill layer style - var fill = fills.firstObject(); - - //Get a random color to fill layer style - var r = getRandomIntInclusive(1,11) - - //Avoid repeat colors - while (lastColor == r) { - var r = Math.floor(Math.random() * 11) - } - // Fill the color - [fill setColor:[MSColor colorWithSVGString: colors[r]]]; - - // Remember last used color - var lastColor = r - } - }