-
Notifications
You must be signed in to change notification settings - Fork 22
/
Toggle Legacy UI (for all scripts).jsx
111 lines (94 loc) · 2.85 KB
/
Toggle Legacy UI (for all scripts).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
/**
* Toggles 'Use Legacy UI' for all installed scripts.
*
* Set line 13 to 'enableLegacy = true' to ENABLE LEGACY UI.
* Set line 13 to 'enableLegacy = false' to DISABLE LEGACY UI.
*
* Note that you'll need to close & relaunch your ScriptUI panels.
*
* @author Zack Lovatt <[email protected]>
* @version 0.3.1
*/
(function toggleLegacyUIForAllScripts() {
var enableLegacy = false;
/**
* Checks whether a folder is an alias, returns resolved route
*
* @param {Folder} folder Folder to check
* @returns {Folder} Resolved path
*/
function checkAlias(folder) {
if (folder.resolve() !== null) {
return folder.resolve();
}
return folder;
}
/**
* Gets array of all installed ScriptUI files
*
* @returns {File[]} Installed SUI Files
*/
function getScriptUIFiles() {
var searchTerm = "*.jsx*"; // returns jsx and jsxbin files
var aeVersion = parseFloat(app.version).toFixed(1);
var win = $.os.indexOf("Windows") !== -1;
var aeFolder = checkAlias(Folder.appPackage);
// get parent folder for macs
if (!win) {
aeFolder = checkAlias(aeFolder.parent);
}
// Check the main install folder
var scriptUIPanelPath = aeFolder.fullName + "/Scripts/ScriptUI Panels";
var scriptUIPanelFolder = checkAlias(new Folder(scriptUIPanelPath));
var scriptFiles = scriptUIPanelFolder.getFiles(searchTerm);
// Now, check the no-admin user scriptUI folder on Windows
if (win) {
var userScriptUIPath =
checkAlias(Folder.userData).fullName +
"/Adobe/After Effects/" +
aeVersion +
"/Scripts/ScriptUI Panels";
var userScriptUIFolder = checkAlias(new Folder(userScriptUIPath));
if (userScriptUIFolder.exists) {
scriptFiles = scriptFiles.concat(
userScriptUIFolder.getFiles(searchTerm)
);
}
}
return scriptFiles;
}
/**
* Toggles preferences setting for a given script
*
* @param {string} scriptFileName JSX Filename
* @returns {boolean} Whether operation succeeded
*/
function toggleLegacyUI(scriptFileName) {
var prefSection = "Pref_SUI_PANEL_USES_LEGACY_SKIN";
var prefKey = "Adobe Scripting-" + scriptFileName;
var prefFile = PREFType.PREF_Type_MACHINE_INDEPENDENT;
try {
if (!app.preferences.havePref(prefSection, prefKey, prefFile)) {
return false;
}
app.preferences.savePrefAsBool(
prefSection,
prefKey,
enableLegacy,
prefFile
);
} catch (e) {
alert(e);
return false;
}
return true;
}
var scriptUIFiles = getScriptUIFiles();
for (var ii = 0, il = scriptUIFiles.length; ii < il; ii++) {
var script = scriptUIFiles[ii];
var scriptFileName = script.displayName;
toggleLegacyUI(scriptFileName);
}
app.preferences.saveToDisk();
app.preferences.reload();
})();