-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathLoad Last Autosave.jsx
101 lines (82 loc) · 2.21 KB
/
Load Last Autosave.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
/**
* Loads last autosave file, if one exists
*
* @author Zack Lovatt <[email protected]>
* @version 0.1.0
*/
(function loadLastAutosave() {
var autosaveFolderName = "Adobe After Effects Auto-Save";
/**
* Gets AE autosave directory
*
* @return {Folder} Autosave directory
*/
function _getAutosaveDirectory() {
var saveToCustom = app.preferences.getPrefAsBool(
"Auto Save",
"Save To Custom Location",
PREFType.PREF_Type_MACHINE_INDEPENDENT
);
var autosavePath = "";
if (saveToCustom) {
autosavePath = app.preferences.getPrefAsString(
"Auto Save",
"Auto Save Folder",
PREFType.PREF_Type_MACHINE_INDEPENDENT
);
} else {
var aep = app.project.file;
if (!aep) {
throw new Error("AEP not saved!");
}
var aepDir = aep.parent;
autosavePath = aepDir.fsName + "/" + autosaveFolderName;
}
var autosaveDir = new Folder(autosavePath);
if (!autosaveDir.exists) {
throw new Error(
"Can't find autosave folder at " + autosaveDir.fsName + " !"
);
}
return autosaveDir;
}
/**
* Gets the newest file in a directory
*
* @param {Folder} directory Directory to get file from
* @returns {File} Newest file
*/
function _getNewestFile(directory) {
var files = directory.getFiles("*.aep");
if (files.length === 0) {
throw new Error("No autosave files in " + directory.fsName + " !");
}
var latestModified = new Date(0);
var newestFile;
var currentFilename;
if (app.project.file) {
currentFilename = app.project.file.displayName.split(".aep")[0];
}
for (var ii = 0, il = files.length; ii < il; ii++) {
var file = files[ii];
if (!(file instanceof File)) {
continue;
}
if (currentFilename && file.displayName.indexOf(currentFilename) === -1) {
continue;
}
if (file.modified > latestModified) {
latestModified = file.modified;
newestFile = file;
}
}
return newestFile;
}
try {
var autosaveDir = _getAutosaveDirectory();
var newestFile = _getNewestFile(autosaveDir);
app.open(newestFile);
} catch (e) {
alert(e);
}
})();