/** Runs the macro contained in the string <code>macro</code>. The optional string argument can be retrieved in the called macro using the getArgument() macro function. Returns any string value returned by the macro, null if the macro does not return a value, or "[aborted]" if the macro was aborted due to an error. */ public static String runMacro(String macro, String arg) { Macro_Runner mr = new Macro_Runner(); return mr.runMacro(macro, arg); }
/** Downloads BeanShell or Jython interpreter using a separate thread. */ public void run() { if (downloading || downloadUrl==null) return; downloading = true; boolean ok = Macro_Runner.downloadJar(downloadUrl); downloading = false; }
/** Runs the specified macro or script file in the current thread. The file is assumed to be in the macros folder unless <code>name</code> is a full path. The optional string argument (<code>arg</code>) can be retrieved in the called macro or script using the getArgument() function. Returns any string value returned by the macro, or null. Scripts always return null. The equivalent macro function is runMacro(). */ public static String runMacroFile(String name, String arg) { Macro_Runner mr = new Macro_Runner(); return mr.runMacroFile(name, arg); }
String runMacro(boolean eval) { interp.getLeftParen(); String name = getString(); String arg = null; if (interp.nextToken()==',') { interp.getComma(); arg = getString(); } interp.getRightParen(); if (eval) { if (arg!=null && (name.equals("script")||name.equals("js"))) return (new Macro_Runner()).runJavaScript(arg, ""); else if (arg!=null && (name.equals("bsh"))) return Macro_Runner.runBeanShell(arg,""); else if (arg!=null && (name.equals("python"))) return Macro_Runner.runPython(arg,""); else return IJ.runMacro(name, arg); } else return IJ.runMacroFile(name, arg); }
if (arg==null) arg = ""; if (name.startsWith("ij.jar:")) return runMacroFromIJJar(name, arg); boolean fullPath = name.startsWith("/") || name.startsWith("\\") || name.indexOf(":\\")==1 || name.indexOf(":/")==1; String path = name; OpenDialog.setLastName(f.getName()); if (name.endsWith(".js")) return runJavaScript(macro, arg); else if (name.endsWith(".bsh")) return runBeanShell(macro, arg); else if (name.endsWith(".py")) return runPython(macro, arg); else return runMacro(macro, arg);
/** Runs a BeanShell script on the current thread, passing a string argument, which the script can retrieve using the getArgument() function. Returns, as a string, the last expression evaluated by the script. Uses the plugin at http://imagej.nih.gov/ij/plugins/bsh/ to run the script. */ public static String runBeanShell(String script, String arg) { if (arg==null) arg = ""; Object bsh = IJ.runPlugIn("bsh", ""); if (bsh==null) { boolean ok = downloadJar("/plugins/bsh/BeanShell.jar"); if (ok) bsh = IJ.runPlugIn("bsh", ""); } if (bsh!=null) return runScript(bsh, script, arg); else return null; }
if (name!=null) { path = directory+name; runMacroFile(path, null); if (Recorder.record) { if (Recorder.scriptMode()) runMacroFromJar(name.substring(4), null); else if (name.startsWith("ij.jar:")) runMacroFromIJJar(name, null); else if (name.endsWith("Tool.ijm") || name.endsWith("Tool.txt") || name.endsWith("Menu.ijm") || name.endsWith("Menu.txt")) else path = Menus.getPlugInsPath() + name; runMacroFile(path, null);
return runMacroFile(name, arg); InputStreamReader isr = new InputStreamReader(is); StringBuffer sb = new StringBuffer(); return runMacro(macro, arg); else return null;
importClass(Packages.ij.plugin.Macro_Runner); var i = 42; mr = new Macro_Runner(); mr.runMacro("print(getArgument());", i);
return getWindowTitle(); } else if (lowercaseKey.equals("macro.filepath")) { String path = Macro_Runner.getFilePath(); return path!=null?path:"null"; } else {
String runMacro(boolean eval) { interp.getLeftParen(); String name = getString(); String arg = null; if (interp.nextToken()==',') { interp.getComma(); arg = getString(); } interp.getRightParen(); if (eval) { if (arg!=null && (name.equals("script")||name.equals("js"))) return (new Macro_Runner()).runJavaScript(arg, ""); else if (arg!=null && (name.equals("bsh"))) return Macro_Runner.runBeanShell(arg,""); else if (arg!=null && (name.equals("python"))) return Macro_Runner.runPython(arg,""); else return IJ.runMacro(name, arg); } else return IJ.runMacroFile(name, arg); }
if (arg==null) arg = ""; if (name.startsWith("ij.jar:")) return runMacroFromIJJar(name, arg); boolean fullPath = name.startsWith("/") || name.startsWith("\\") || name.indexOf(":\\")==1 || name.indexOf(":/")==1; String path = name; OpenDialog.setLastName(f.getName()); if (name.endsWith(".js")) return runJavaScript(macro, arg); else if (name.endsWith(".bsh")) return runBeanShell(macro, arg); else if (name.endsWith(".py")) return runPython(macro, arg); else return runMacro(macro, arg);
/** Runs a Python script on the current thread, passing a string argument, which the script can retrieve using the getArgument() function. Returns, as a string, the value of the variable 'result'. For example, a Python script containing the line "result=123" will return the string "123". Uses the plugin at http://imagej.nih.gov/ij/plugins/jython/ to run the script. */ public static String runPython(String script, String arg) { if (arg==null) arg = ""; Object jython = IJ.runPlugIn("Jython", ""); if (jython==null) { boolean ok = downloadJar("/plugins/jython/Jython.jar"); if (ok) jython = IJ.runPlugIn("Jython", ""); } if (jython!=null) return runScript(jython, script, arg); else return null; }
if (name!=null) { path = directory+name; runMacroFile(path, null); if (Recorder.record) { if (Recorder.scriptMode()) runMacroFromJar(name.substring(4), null); else if (name.startsWith("ij.jar:")) runMacroFromIJJar(name, null); else if (name.endsWith("Tool.ijm") || name.endsWith("Tool.txt") || name.endsWith("Menu.ijm") || name.endsWith("Menu.txt")) else path = Menus.getPlugInsPath() + name; runMacroFile(path, null);
return runMacroFile(name, arg); InputStreamReader isr = new InputStreamReader(is); StringBuffer sb = new StringBuffer(); return runMacro(macro, arg); else return null;
return getWindowTitle(); } else if (lowercaseKey.equals("macro.filepath")) { String path = Macro_Runner.getFilePath(); return path!=null?path:"null"; } else {
/** Runs the macro contained in the string <code>macro</code>. The optional string argument can be retrieved in the called macro using the getArgument() macro function. Returns any string value returned by the macro, null if the macro does not return a value, or "[aborted]" if the macro was aborted due to an error. */ public static String runMacro(String macro, String arg) { Macro_Runner mr = new Macro_Runner(); return mr.runMacro(macro, arg); }
/** Runs a BeanShell script on the current thread, passing a string argument, which the script can retrieve using the getArgument() function. Returns, as a string, the last expression evaluated by the script. Uses the plugin at http://imagej.nih.gov/ij/plugins/bsh/ to run the script. */ public static String runBeanShell(String script, String arg) { if (arg==null) arg = ""; Object bsh = IJ.runPlugIn("bsh", ""); if (bsh==null) { boolean ok = downloadJar("/plugins/bsh/BeanShell.jar"); if (ok) bsh = IJ.runPlugIn("bsh", ""); } if (bsh!=null) return runScript(bsh, script, arg); else return null; }
/** Runs the specified macro or script file in the current thread. The file is assumed to be in the macros folder unless <code>name</code> is a full path. The optional string argument (<code>arg</code>) can be retrieved in the called macro or script using the getArgument() function. Returns any string value returned by the macro, or null. Scripts always return null. The equivalent macro function is runMacro(). */ public static String runMacroFile(String name, String arg) { Macro_Runner mr = new Macro_Runner(); return mr.runMacroFile(name, arg); }
/** Downloads BeanShell or Jython interpreter using a separate thread. */ public void run() { if (downloading || downloadUrl==null) return; downloading = true; boolean ok = Macro_Runner.downloadJar(downloadUrl); downloading = false; }