-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnextFrame.jsx
More file actions
133 lines (116 loc) · 4.66 KB
/
nextFrame.jsx
File metadata and controls
133 lines (116 loc) · 4.66 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
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
// Script by Vince Petaccio of PetRok Studios. | www.PetRokStudios.com
// Ensure a document is open
if ( documents.length > 0 )
{
// Change dialog settings
var originalDialogMode = app.displayDialogs;
app.displayDialogs = DialogModes.ERROR;
try
{
// Get the document
var docRef = activeDocument;
// Get the path for the document
var filePath = docRef.path + '/';
// Get the filename of the document
var fileNameNoExtension = docRef.name;
// Split the filename at the dots
fileNameNoExtension = fileNameNoExtension.split( "." );
// If there's a dot, remove everything after the last dot
if ( fileNameNoExtension.length > 1 ) {
// Get the file type
fileType = fileNameNoExtension[fileNameNoExtension.length-1];
// Decrement the filename object by removing the last element (the stuff after the last .)
fileNameNoExtension.length--;
// Reconnect everything BEFORE the first .
fileNameNoExtension = fileNameNoExtension.join(".");
}
// Get the last five characters of the filename
lastFive = fileNameNoExtension.slice(-5);
allButFive = fileNameNoExtension.slice(0,-6);
// Check whether the last five characters are digits
newDoc = isNaN(parseInt(lastFive))
// Create the needName switch
needName = 1
// If this is a new document, then add _00000 to the file name
if (newDoc) {
// Make the new file name
newFileName = fileNameNoExtension + '_00000';
allButFive = fileNameNoExtension;
lastFive = '00000';
// Do the saving. Check whether file_00000 exists first.
needName = makeFile(fileType.toLowerCase(), docRef, newFileName)
}
// Otherwise, find the lowest number of the file name that does not exist, starting at the index of the file name's digits. Get the file number
fileNumber = Number(lastFive);
while (needName) {
// Increment the file number
fileNumber = fileNumber + 1;
// Make the file number 4 digits with zeros
switch ((fileNumber.toString()).length) {
case 1:
newFileName = allButFive + '_0000' + fileNumber.toString();
break;
case 2:
newFileName = allButFive + '_000' + fileNumber.toString();
break;
case 3:
newFileName = allButFive + '_00' + fileNumber.toString();
break;
case 4:
newFileName = allButFive + '_0' + fileNumber.toString();
break;
case 5:
newFileName = allButFive + "_" + fileNumber.toString();
break;
}
// Do the saving
needName = makeFile(fileType.toLowerCase(), docRef, newFileName)
}
}
catch(e)
{
// An error occured; restore dialog mode and display the error
app.displayDialogs = originalDialogMode;
throw e;
}
}
else
{
alert( "There's no file open! GET TO WORK!!!! :]");
}
// Function for saving the file
function makeFile(fileType, docRef, newFileName) {
thisSameFile = docRef.path + '/' + newFileName + '.' + fileType;
saveFile = new File(thisSameFile);
if (saveFile.exists) {
return 1;
}
switch (fileType) {
case 'psd': // Photoshop file
saveOpt = new PhotoshopSaveOptions();
saveOpt.embedColorProfile = true;
saveOpt.layers = true;
break;
case 'jpg': // JPEG file
saveOpt = new JPEGSaveOptions();
saveOpt.embedColorProfile = true;
saveOpt.formatOptions = FormatOptions.STANDARDBASELINE;
saveOpt.matte = MatteType.NONE;
saveOpt.quality = 12;
break;
case 'png': // PNG file
saveOpt = new PNGSaveOptions();
saveOpt.compression = 0;
break;
case 'tif': // TIFF file
saveOpt = new TiffSaveOptions();
saveOpt.embedColorProfile = true;
saveOpt.layers = false;
saveOpt.transparency = true;
break;
}
app.activeDocument.saveAs(saveFile,saveOpt,true,Extension.LOWERCASE);
app.activeDocument.close(saveOpt.DONOTSAVECHANGES);
open(saveFile);
return 0;
}