This repository has been archived by the owner on Dec 6, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExport AppIcons.jsx
277 lines (258 loc) · 7.22 KB
/
Export AppIcons.jsx
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
/*
* Export AppIcon v0.0.2
* Get the latest version at https://github.com/andykog/ExportAppIcon
*/
var document = app.activeDocument;
var exportableArtboards = {};
var exportableArtboardsCount = 0;
var defaultExport = function(selectedFolder) {
var expFolder = selectedFolder;
for (var i = 0; i < document.artboards.length; i++) {
if (exportableArtboards[i] !== true) continue;
document.artboards.setActiveArtboardIndex(i);
var artboard = document.artboards[i];
if (exportableArtboardsCount > 1) {
var artboardFolderName = (artboard.name.match(/[\w-]/g) || ['Artboard ' + i]).join('');
expFolder = new Folder(selectedFolder.fsName + '/' + artboardFolderName);
if (!expFolder.exists) expFolder.create();
}
var artboardWidth = artboard.artboardRect[2] - artboard.artboardRect[0]; // Don't ask me why
var artboardHeight = artboard.artboardRect[1] - artboard.artboardRect[3];
var fileName = this.tip.replace(/[();]/g, '').replace(/\s/g, '_') + '_' + this.name + '.png';
var file = new File(expFolder.fsName + '/' + fileName);
var options = new ExportOptionsPNG24();
options.transparency = true;
options.artBoardClipping = true;
options.antiAliasing = true;
options.verticalScale = this.size / artboardHeight * 100;
options.horizontalScale = this.size / artboardWidth * 100;
document.exportFile(file, ExportType.PNG24, options);
};
};
var exportGroups = [
{
groupName: 'iPhone',
options: [
{
name: '29pt @2x',
tip: 'iPhone Spotlight iOS 5,6; Settings iOS 5-9',
size: 58,
enabled: true,
handleExport: defaultExport
},
{
name: '29pt @3x',
tip: 'iPhone Spotlight iOS 5,6; Settings iOS 5-9',
size: 87,
enabled: true,
handleExport: defaultExport
},
{
name: '40pt @2x',
tip: 'iPhone Spotlight iOS 7-9',
size: 80,
enabled: true,
handleExport: defaultExport
},
{
name: '40pt @3x',
tip: 'iPhone Spotlight iOS 7-9',
size: 120,
enabled: true,
handleExport: defaultExport
},
{
name: '60pt @2x',
tip: 'iPhone App iOS 7-9',
size: 120,
enabled: true,
handleExport: defaultExport
},
{
name: '60pt @3x',
tip: 'iPhone App iOS 7-9',
size: 180,
enabled: true,
handleExport: defaultExport
}
]
},
{
groupName: 'iPad',
options: [
{
name: '29pt @1x',
tip: 'iPad Settings iOS 5-9',
size: 29,
enabled: true,
handleExport: defaultExport
},
{
name: '29pt @2x',
tip: 'iPad Settings iOS 5-9',
size: 58,
enabled: true,
handleExport: defaultExport
},
{
name: '40pt @1x',
tip: 'iPad Spotlight iOS 7-9',
size: 40,
enabled: true,
handleExport: defaultExport
},
{
name: '40pt @2x',
tip: 'iPad Spotlight iOS 7-9',
size: 80,
enabled: true,
handleExport: defaultExport
},
{
name: '76pt @1x',
tip: 'iPad App iOS 7-9',
size: 76,
enabled: true,
handleExport: defaultExport
},
{
name: '76pt @2x',
tip: 'iPad App iOS 7-9',
size: 152,
enabled: true,
handleExport: defaultExport
},
{
name: '83.5pt @2x',
tip: 'iPad Pro App iOS 7-9',
size: 167,
enabled: true,
handleExport: defaultExport
}
]
},
{
groupName: 'Apple Watch',
options: [
{
name: '24pt @2x',
tip: 'Apple Watch Notification Center 38 mm',
size: 48,
enabled: true,
handleExport: defaultExport
},
{
name: '27.5pt @2x',
tip: 'Apple Watch Notification Center 42 mm',
size: 55,
enabled: true,
handleExport: defaultExport
},
{
name: '29pt @2x',
tip: 'Apple Watch Companion Settings',
size: 58,
enabled: true,
handleExport: defaultExport
},
{
name: '29pt @3x',
tip: 'Apple Watch Companion Settings',
size: 87,
enabled: true,
handleExport: defaultExport
},
{
name: '40pt @2x',
tip: 'Apple Watch Home Screen (All), Long Look (38 mm)',
size: 80,
enabled: true,
handleExport: defaultExport
},
{
name: '44pt @2x',
tip: 'Apple Watch Long Look 42 mm',
size: 88,
enabled: true,
handleExport: defaultExport
},
{
name: '86pt @2x',
tip: 'Apple Watch Short Look 38 mm',
size: 172,
enabled: true,
handleExport: defaultExport
},
{
name: '98pt @2x',
tip: 'Apple Watch Short Look 42 mm',
size: 196,
enabled: true,
handleExport: defaultExport
}
]
},
{
groupName: 'Other',
options: [
{
name: '1024pt',
tip: 'Itunes Artwork',
size: 1024,
enabled: false,
handleExport: defaultExport
}
]
}
];
if (document && document.artboards.length > 0) {
var dialog = new Window('dialog', 'Export for iOS');
var group = dialog.add('group')
group.alignChildren = 'top';
if (document.artboards.length > 1) {
var panel = group.add('panel', undefined, "Artboards");
panel.alignChildren = 'left';
for (var i = 0; i < document.artboards.length; i++) {
exportableArtboards[i] = true;
var artboard = document.artboards[i];
var checkbox = panel.add('checkbox', undefined, '\u00A0' + artboard.name);
checkbox.value = exportableArtboards[i];
checkbox._i = i;
checkbox.onClick = function() { exportableArtboards[this._i] = !exportableArtboards[this._i]; };
}
} else if (document.artboards.length === 1) {
exportableArtboards[0] = true;
}
for (var i = 0; i < exportGroups.length; i++) {
var array = exportGroups[i].options;
var panel = group.add('panel', undefined, exportGroups[i].groupName);
panel.alignChildren = 'left';
for(var ii = 0; ii < array.length; ii++) {
var checkbox = panel.add('checkbox', undefined, '\u00A0' + array[ii].name);
checkbox.value = array[ii].enabled || false;
checkbox.helpTip = array[ii].tip
checkbox._option = array[ii];
checkbox.onClick = function() { this._option.enabled = !this._option.enabled; };
}
}
var okButton = dialog.add('group').add('button', undefined, 'Export');
okButton.onClick = function() {
for (var i = 0; i < document.artboards.length; i++) {
if (exportableArtboards[i]) exportableArtboardsCount++;
}
if (exportableArtboardsCount > 0) {
var selectedFolder = Folder.selectDialog('Where to handleExport the exported files?');
if (selectedFolder) {
for (var i = 0; i < exportGroups.length; i++) {
var options = exportGroups[i].options;
for (var ii = 0; ii < options.length; ii++) {
var option = options[ii];
if (option.enabled) option.handleExport(selectedFolder);
}
}
}
}
dialog.close();
};
dialog.show();
}