-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathscript.cocoascript
More file actions
75 lines (51 loc) · 1.91 KB
/
script.cocoascript
File metadata and controls
75 lines (51 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
function onRun(context) {
// 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
}
}
}