// A tool making plugin shortcut for macros and tools: // A plugin shortcut is available after ImageJ restarting, in the Plugins",choicemenu,toString(optionchoice)); Dialog.show(); optionchoice= Dialog.getChoice(); if (optionchoice == "Only macro sets and tools") sortoption=0; if (optionchoice == "All macros") sortoption=1; macroname = GetMacroListMenu (); InstallPluginsStarter(macroname,1); if (File.exists(getDirectory("macros") + "tools/MacroPluginShortcutsTool.txt")) { macroname="MacroPluginShortcutsTool.txt";KindOfMacro= 1; InstallPluginsStarter(macroname,0); } } function InstallPluginsStarter(macroname,comment) { codemacrostarter ="run\(\"Install...\", \"install=[\"+getDirectory(\"macros\")+\"" + macroname + "\]\"\);"; codetoolstarter = "run\(\"Install...\", \"install=[\"+getDirectory(\"macros\")+\"tools/" + macroname + "\]\"\);"; StarterDir = getDirectory("startup") + favoritefoldername + "/"; if (getDirectory("plugins") == "") exit ("Unable to find the Plugins directory; something wrong in the ImageJ folder."); pluginlocation = getDirectory("plugins"); pluginname = ShortMacroName (macroname); // Create a repertory in the ImageJ Plugins folder. StarterDir = pluginlocation+favoritefoldername+File.separator; File.makeDirectory(StarterDir); if (!File.exists(StarterDir)) exit ("Unable to create Image Bio Methods Macros directory, something wrong in the ImageJ folder."); starterplugin = StarterDir + pluginname +"_ .ijm"; //Write the new macro codestarter=codemacrostarter; if (KindOfMacro == 1) codestarter=codetoolstarter; f= File.open(starterplugin); print (f,codestarter); File.close(f); if (comment==1) { showMessage ("Installation of the Plugin \"" +pluginname+ "\" is completed.\nIt will be available after ImageJ restarting, in the \"Plugins->" + favoritefoldername + "\" menu."); } } function GetMacroListMenu () { if (getDirectory("macros") == "") exit ("Unable to find the macros directory; something wrong in the ImageJ folder."); macrostoolslocation = getDirectory("macros") + "tools/"; if (File.isDirectory(macrostoolslocation) == 0) exit ("Unable to find the tools directory on the macros directory; something wrong in the ImageJ folder."); macrosfolder = getDirectory("macros"); listofmacro = getFileList(macrosfolder); listoftools = getFileList(macrostoolslocation); NbMacro= getMacroNumber (listofmacro,sortoption,macrosfolder); NbTools= getMacroNumber (listoftools,sortoption,macrostoolslocation); NbToolsandMacros=(NbMacro + NbTools); MacrosandTools1 = newArray(NbToolsandMacros+2); MacrosandTools1[0] =-1; MacrosandTools2 = newArray(NbToolsandMacros+2); MacrosandTools2[0] ="--- Macro List ---";PlaceOfMacro=1; PlaceintheMenu(MacrosandTools1,MacrosandTools2,PlaceOfMacro,listofmacro,0,sortoption,macrosfolder); MacrosandTools2[NbMacro+1]="--- Tools List ---"; PlaceintheMenu(MacrosandTools1,MacrosandTools2,(NbMacro+2),listoftools,1,sortoption,macrostoolslocation); macrochosen = "--- Macro List ---"; showProgress(1.0); while (macrochosen == "--- Tools List ---" || macrochosen == "--- Macro List ---"){ Dialog.create("Macro & Tool Choice"); Dialog.addMessage("Choose a Macro or a Tool in the popup menu\n(list of macros, following by the list of tools):"); Dialog.addChoice("->",MacrosandTools2); Dialog.addMessage("\nNumber of macros="+ NbToolsandMacros + " ("+NbMacro+" \"Macros\", "+NbTools+" \"Tools\")"); Dialog.show(); macrochosen= Dialog.getChoice(); for (i=1; i<=NbToolsandMacros; i++) { if (MacrosandTools2[i] == macrochosen) KindOfMacro = MacrosandTools1[i]; } } return macrochosen; } function ShortMacroName (longname) { shortnames = longname; if (endsWith(longname, ".txt") || endsWith(longname, ".ijm")) shortnames = substring(longname, 0, (lengthOf(longname)-4)); return shortnames; } function getMacroNumber (lmacros,sortoption,dirmac) { NumberOfMacro=0; for (i=0; i1) testmac=1; if (indexOf(macrocontent, "Tool")>0) testmac=1; return testmac; } function nmac(macrotext,kindof){ nummac=0; while (indexOf(macrotext, kindof)> -1) { if (indexOf(macrotext, kindof)>-1){ macrotext=substring(macrotext, (indexOf(macrotext, kindof)+lengthOf(kindof)), lengthOf(macrotext)); index=0; while (indexOf(macrotext, " ") ==0){macrotext=substring(macrotext,1, (lengthOf(macrotext)));} if (startsWith(macrotext, "\"") || startsWith(macrotext, "'" )) nummac ++; } } return nummac; }