-
Notifications
You must be signed in to change notification settings - Fork 1
/
SaveDocsAsTIFF.jsx
56 lines (47 loc) · 1.88 KB
/
SaveDocsAsTIFF.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
/**********************************************************************/
/* Author: Michael J. Lehrke */
/* License: GNU GPLv3 */
/* Copyright: 2017 */
/* */
/* Description: saves all open Illustrator documents as TIFF files */
/**********************************************************************/
try {
if (app.documents.length > 0) {
var destinationFolder = Folder(app.activeDocument.path).selectDlg();
if (!destinationFolder || destinationFolder === null) {
throw new Error('Destination folder was not set or does not exist.');
}
var confirmAction = confirm('This will overwrite TIFF files with the same file name, continue?');
if (!confirmAction) {
throw new Error('Operation cancelled');
}
var options = new ExportOptionsTIFF();
options.resolution = 300.0;
for (i = 0; i < app.documents.length; i++) {
var newFile = createNewFile(app.documents[i].name, '.tif', destinationFolder);
app.documents[i].exportFile(newFile, ExportType.TIFF, options);
}
alert('Successfully exported the TIFF files.');
} else {
throw new Error('No documents are open.');
}
}
catch(e) {
alert(e.message, "TIFF Script Error", true);
}
function createNewFile(fileName, fileExtension, fileDestination) {
var fullName = "";
if (fileName.indexOf('.') < 0) {
fullName = fileName + fileExtension;
} else {
fullName = fileName.substring(0, fileName.lastIndexOf('.'));
fullName += fileExtension;
}
var newFile = new File(fileDestination + '/' + fullName);
if (newFile.open('w')) {
newFile.close();
} else {
throw new Error('Access/permission denied. Cannot save file in this location.');
}
return newFile;
}