-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathWrite Layer Names to File.jsx
55 lines (47 loc) · 1.22 KB
/
Write Layer Names to File.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
/**
* Write layer names in comp to a file
*
* @author Zack Lovatt <[email protected]>
* @version 0.2.1
*/
(function writeLayerNamesToFile() {
/**
* Writes a file to path with contents
* Doesn't check for encoding, the folder existing, overwrite checks, etc.
* Super straightforward.
*
* @param {File | String} path File path to write to
* @param {String} contents File contents
*/
function writeFile(path, contents) {
var fileObj = path instanceof File ? path : new File(path);
fileObj.open('w');
fileObj.write(contents);
fileObj.close();
}
var comp = app.project.activeItem;
if (!(comp && comp instanceof CompItem)) {
alert('Open a comp!');
return;
}
var layers = comp.layers;
var layerNames = [];
for (var ii = 1, il = layers.length; ii <= il; ii++) {
layerNames.push(layers[ii].name);
}
var defaultPath = Folder.desktop.fullName + '/Layer Names.txt';
var outputFile = new File(defaultPath).saveDlg(
'Choose output file',
'txt:*.txt;'
);
if (!outputFile) {
alert('Output canceled!');
return;
}
try {
writeFile(outputFile, layerNames.join('\n'));
alert('Saved file to ' + String(outputFile));
} catch (e) {
alert(e);
}
})();