Skip to content

Commit

Permalink
allow folders outside of script folder path
Browse files Browse the repository at this point in the history
  • Loading branch information
grefel committed May 5, 2019
1 parent 46cbf57 commit 15c8646
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions startup scripts/addScriptFolderToMenu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@

var px = {
projectName: "AddScriptFolderToMenu",
version: "2019-01-31-v1.1",
version: "2019-05-05-v1.2",

scriptFolderMenuFolderName: "Scripts Menu",
scriptMenuFolderName: app.scriptPreferences.scriptsFolder + "/" + "Scripts Menu",
// scriptMenuFolderName: "/Users/hp/github/addScriptFolderToMenu/Scripts Menu",

scriptMenuName: localize({ en: "Scripts", de: "Skripte" }),

position: "table", // help
Expand Down Expand Up @@ -602,7 +604,7 @@ $.global.hasOwnProperty('idsLog') || (function (HOST, SELF) {
*/
getLogFile: function () {
return logFile;
}
}
}
};
})($.global, { toString: function () { return 'idsLog'; } });
Expand Down Expand Up @@ -639,24 +641,24 @@ function main() {

function installMenu() {
// User Folder
var scriptFolderMenuPath = Folder(app.scriptPreferences.scriptsFolder + "/" + px.scriptFolderMenuFolderName);
if (scriptFolderMenuPath.alias) {
var scriptMenuFolderPath = Folder(px.scriptMenuFolderName);
if (scriptMenuFolderPath.alias) {
try {
scriptFolderMenuPath = scriptFolderMenuPath.resolve();
scriptMenuFolderPath = scriptMenuFolderPath.resolve();
}
catch (e) {
log.warn(e);
log.warn("Could not resolve alias. Check your alias file [" + scriptFolderMenuPath + "]");
log.warn("Could not resolve alias. Check your alias file [" + scriptMenuFolderPath + "]");
return;
}
}

if (scriptFolderMenuPath.exists) {
if (scriptMenuFolderPath.exists) {
// analyse scripts in scriptfolder
var scriptsArray = [];
scriptsArray = analyseScriptsFolder(scriptFolderMenuPath, scriptsArray);
scriptsArray = analyseScriptsFolder(scriptMenuFolderPath, scriptsArray);
if (scriptsArray.length == 0) {
log.warn("No script files found in folder [" + scriptFolderMenuPath + "]");
log.warn("No script files found in folder [" + scriptMenuFolderPath + "]");
return;
}

Expand Down Expand Up @@ -688,7 +690,7 @@ function installMenu() {

}
else {
log.info("Could not find a Folder [" + px.scriptFolderMenuFolderName + "] in [" + app.scriptPreferences.scriptsFolder + "]");
log.info("Could not find the folder [" + px.scriptMenuFolderName + "]");
}
}

Expand Down Expand Up @@ -768,7 +770,7 @@ function analyseScriptsFolder(folder, scriptsArray) {

function checkForChildren(child) {
var children = child.getFiles();
for (i = 0; i < children.length; i++) {
for (i = 0; i < children.length; i++) {
child = children[i];
if (child instanceof Folder && checkForChildren(child)) {
return true;
Expand Down Expand Up @@ -855,13 +857,13 @@ function showInfoAndUninstall() {

dialogWin.gText = dialogWin.add("group");

dialogWin.gText.stMsg = dialogWin.gText.add("statictext", undefined, localize({ en: "This menu shows scripts from " + px.scriptFolderMenuFolderName, de: "Dieses Menü zeigt die Skripte aus dem Ordner " + px.scriptFolderMenuFolderName }));
dialogWin.gText.stMsg = dialogWin.gText.add("statictext", undefined, localize({ en: "This menu shows scripts from " + px.scriptMenuFolderName, de: "Dieses Menü zeigt die Skripte aus dem Ordner " + px.scriptMenuFolderName }));
dialogWin.gText.stMsg.maximumSize.height = 300;
dialogWin.gText.stMsg.minimumSize.width = 350;

dialogWin.gText.btOpenFolderLocation = dialogWin.gText.add("button", undefined, localize({ en: "Show folder", de: "Ordner anzeigen" }));
dialogWin.gText.btOpenFolderLocation.onClick = function () {
Folder(app.scriptPreferences.scriptsFolder + "/" + px.scriptFolderMenuFolderName).execute();
Folder(px.scriptMenuFolderName).execute();
dialogWin.close(0);
}

Expand Down

0 comments on commit 15c8646

Please sign in to comment.