Opens and runs the specified macro file (.txt or .ijm) or script file (.js, .bsh or .py) on the current thread. Displays a file open dialog if name is an empty string. The macro or script is assumed to be in the ImageJ plugins folder if name is not a full path.
(String name)
| 31 | is an empty string. The macro or script is assumed to be in the ImageJ |
| 32 | plugins folder if <code>name</code> is not a full path. */ |
| 33 | @AstroImageJ(reason = "Fix classloader", modified = true) |
| 34 | public void run(String name) { |
| 35 | if (IJ.debugMode) |
| 36 | IJ.log("Macro_Runner.run(): "+name); |
| 37 | Thread thread = Thread.currentThread(); |
| 38 | String threadName = thread.getName(); |
| 39 | if (!threadName.endsWith("Macro$")) { |
| 40 | if (name.endsWith(".js")||name.endsWith(".bsh")||name.endsWith(".py")) |
| 41 | thread.setName(threadName+"_Script_Macro$"); |
| 42 | else |
| 43 | thread.setName(threadName+"_Macro$"); |
| 44 | } |
| 45 | String path = null; |
| 46 | if (name.equals("")) { |
| 47 | OpenDialog od = new OpenDialog("Run Macro or Script...", path); |
| 48 | String directory = od.getDirectory(); |
| 49 | name = od.getFileName(); |
| 50 | if (name!=null) { |
| 51 | path = directory+name; |
| 52 | runMacroFile(path, null); |
| 53 | if (IJ.recording()) { |
| 54 | path = Recorder.fixPath(path); |
| 55 | if (Recorder.scriptMode()) |
| 56 | Recorder.recordCall("IJ.runMacroFile(\""+path+"\");"); |
| 57 | else |
| 58 | Recorder.record("runMacro", path); |
| 59 | } |
| 60 | } |
| 61 | } else if (name.startsWith("JAR:")) |
| 62 | runMacroFromJar(getClass().getClassLoader(), name.substring(4), null); |
| 63 | else if (name.startsWith("ij.jar:")) |
| 64 | runMacroFromIJJar(name, null); |
| 65 | else if (name.endsWith("Tool.ijm") || name.endsWith("Tool.txt") |
| 66 | || name.endsWith("Menu.ijm") || name.endsWith("Menu.txt")) |
| 67 | (new MacroInstaller()).installTool(Menus.getPlugInsPath()+name); |
| 68 | else { |
| 69 | boolean fullPath = name.startsWith("/") || name.startsWith("\\") || name.indexOf(":\\")==1 || name.indexOf(":/")==1; |
| 70 | if (fullPath) |
| 71 | path = name; |
| 72 | else |
| 73 | path = Menus.getPlugInsPath() + name; |
| 74 | runMacroFile(path, null); |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | /** Opens and runs the specified macro or script on the current |
| 79 | thread. The file is assumed to be in the ImageJ/macros folder |
nothing calls this directly
no test coverage detected