/* Allows changes in ImageMagick and Gifsicle paths so that different versions can be tested v210917: First version (just ImageMagick path) v211018: Gifsicle added and changed prefs to being app specific to be consistent with recent macros v211213: fixed function v220121: GnuWin32 added v220628 Changed from convert to magick.exe for IM7. v230720: Removed GnuWin32 ('g32') as all tiff operations now performed with 64-bit ImageMagick. v230720b: Consolidated dialogs. Only logs output on failure. v230803: Replaced getDir for 1.54g10. v260603: Adds more defAppPaths and beautifies. */ macroL = "Set_External_App_Paths_v230803.ijm"; if (!startsWith(getInfo("os.name"), "Windows")) exit("Sorry, this macro currently only works with Windows"); fS = File.separator; ijPath = getDirectory("imagej"); username = getInfo("user.name"); appsPath = substring(ijPath, 0, lengthOf(ijPath) - 1); appsPath = substring(appsPath, 0, lastIndexOf(appsPath, fS)); cProg = "C:" + fS + "Program Files"; defAppPaths = newArray(ijPath + "Apps", "C:" + fS + "Users" + fS + username + fS + "AppData" + fS + "Local" + fS + "Programs" + fS + "ImageMagick", cProg + fS + "Utilities", cProg + " \(x86\)" + fS + "Utilities", cProg, cProg + " \(x86\)", appsPath); prefsPrefix = "asc.external.paths."; iMLoc = "" + fS + "ImageMagick" + fS; iMApp = "magick.exe"; iMAppPrefsSet = prefsPrefix + "imagemagick." + iMApp; gSLoc = "" + fS + "Gifsicle" + fS; gSApp = "gifsicle.exe"; gSAppPrefsSet = prefsPrefix + "gifsicle." + gSApp; iMAppPath = findAppPath("ImageMagick", iMApp, "not found"); if (File.exists(iMAppPath)) iMAppFound = true; else iMAppFound = false; if (iMAppFound) iMRadioButtons = newArray(iMAppPath); else iMRadioButtons = newArray(); for (i = 0, j = iMRadioButtons.length; i < defAppPaths.length; i++) { appPath = defAppPaths[i] + iMLoc + iMApp; if (File.exists(appPath)) { if (appPath != iMAppPath) { iMRadioButtons[j] = appPath; j++; } } } iMRadioButtons = Array.concat(iMRadioButtons, "Use entered location below"); gSAppPath = findAppPath("Gifsicle", gSApp, "not found"); if (File.exists(gSAppPath)) gSAppFound = true; else gSAppFound = false; gSRadioButtons = newArray(); jStart = 0; if (gSAppFound) { gSRadioButtons[0] = gSAppPath; jStart++; } for (i = 0, j = jStart; i < lengthOf(defAppPaths); i++) { gSAppPath = defAppPaths[i] + gSLoc + gSApp; if (File.exists(gSAppPath)) { // && gSAppPath!=gSAppPath) { if (gSAppPath != gSAppPath) { gSRadioButtons[j] = gSAppPath; j++; } } } gSRadioButtons = Array.concat(gSRadioButtons, "Use entered location below"); Dialog.create(macroL); Dialog.addMessage("Select location to be saved at " + iMAppPrefsSet + ":"); if (iMAppFound) Dialog.addMessage("Current setting: " + iMAppPath); Dialog.addRadioButtonGroup("Select path to be saved:_____", iMRadioButtons, iMRadioButtons.length, 1, iMRadioButtons[0]); Dialog.addDirectory("Locate ImageMagick:", "C:" + fS + "Program Files" + fS); Dialog.addMessage("Select location to be saved at " + gSAppPrefsSet + ":"); if (gSAppFound) Dialog.addMessage("Current setting: " + call("ij.Prefs.get", gSAppPrefsSet, "Not Set")); Dialog.addRadioButtonGroup("Select path to be saved:_____", gSRadioButtons, gSRadioButtons.length, 1, gSRadioButtons[0]); Dialog.addDirectory("Locate Gifsicle:", "C:" + fS + "Program Files"); Dialog.show; iMAppPath = Dialog.getRadioButton(); if (startsWith(iMAppPath, "Use")) iMAppPath = Dialog.getString() + iMApp; gSAppPath = Dialog.getRadioButton(); if (startsWith(gSAppPath, "Use")) gSAppPath = Dialog.getString() + gSApp; if (File.exists(iMAppPath)) { call("ij.Prefs.set", iMAppPrefsSet, iMAppPath); testSetting = call("ij.Prefs.get", iMAppPrefsSet, "whoops"); if (testSetting == "whoops") IJ.log("Setting test failed: " + iMAppPrefsSet + ", " + testSetting); } else IJ.log(iMAppPath + " not found so " + iMAppPrefsSet + " not set"); if (File.exists(gSAppPath)) { call("ij.Prefs.set", gSAppPrefsSet, gSAppPath); testSetting = call("ij.Prefs.get", gSAppPrefsSet, "whoops"); if (testSetting == "whoops") IJ.log("Setting test failed: " + gSAppPrefsSet + ", " + testSetting); } else IJ.log(gSAppPath + " not found so " + gSAppPrefsSet + " not set"); /* ( 8(|) ( 8(|) ASC Functions @@@@@:-) @@@@@:-) */ function findAppPath(appName, appEx, defaultPath) { /* v210921 1st version: appName is assumed to be the app folder name, appEx is the executable, default is the default return value v211018: assumes specific executable path stored in prefs Prints message rather than exits when app not found v211213: fixed defaultPath error v211214: Adds additional location as packaged within a Fiji/IJ distribution v220121: Changed fS line v230803: Replaced getDir with getDirectory for ImageJ 1.54g10 v260603: Adds Appdata path and beautifies. v260604: add missing username. */ functionL = "findAppPath_v260604"; fS = File.separator; ijPath = getDirectory("imagej"); appsPath = substring(ijPath, 0, lengthOf(ijPath) - 1); appsPath = substring(appsPath, 0, lastIndexOf(appsPath, fS)); appFound = false; prefsName = "asc.external.paths." + toLowerCase(appName) + "." + appEx; appPath = call("ij.Prefs.get", prefsName, defaultPath); appLoc = "" + fS + appName + fS + appEx; cProg = "C:" + fS + "Program Files"; username = getInfo("user.name"); defAppPaths = newArray(ijPath + "Apps", "C:" + fS + "Users" + fS + username + fS + "AppData" + fS + "Local" + fS + "Programs" + fS + "ImageMagick", cProg + fS + "Utilities", cProg + " \(x86\)" + fS + "Utilities", cProg, cProg + " \(x86\)", appsPath); if (!File.exists(appPath)) { for (i = 0; i < lengthOf(defAppPaths); i++) { if (File.exists(defAppPaths[i])) { appPath = defAppPaths[i]; call("ij.Prefs.set", prefsName, appPath); appFound = true; i = lengthOf(defAppPaths); } } } else appFound = true; if (appFound == false) { Dialog.create("Find location of " + appEx + " version: " + functionL); Dialog.addMessage(appEx + " can provide additional functionality to this macro\nbut has not been found in the expected locations"); Dialog.addCheckbox("Get me out of here, I don't want to try and find " + appName + ", whatever that is", false); Dialog.addFile("Locate " + appEx + ":", "C:" + fS + "Program Files"); Dialog.addMessage("If found, the location will be saved in prefs for future use:\n" + prefsName); Dialog.show; if (Dialog.getCheckbox) appFound = false; else { appPath = Dialog.getString(); if (!File.exists(appPath)) print(appEx + " not found"); else { call("ij.Prefs.set", prefsName, appPath); appFound = true; } } } if (appFound) return appPath; else return defaultPath; }