Re: Get the folder from which a script is running?
Posted by
Gabriel Landini on
Jun 23, 2015; 9:10am
URL: http://imagej.273.s1.nabble.com/Get-the-folder-from-which-a-script-is-running-tp5013224p5013252.html
On Monday 22 Jun 2015 21:32:47 Wayne wrote:
> You can get the folder of a installed macro or script by looking up the
> command name in the list of menu commands. For example, I have a JavaScript
> named Split_Bayer.js in plugins/Tools and this JavaScript
>
> commands = Menus.getCommands();
> name = commands.get("Split Bayer");
> if (name==null) name="null";
> start = name.indexOf("\"");
> end = name.indexOf("/");
> print("folder="+name.substring(start+1,end));
For some reason in linux, I get this error:
sun.org.mozilla.javascript.WrappedException: Wrapped
java.lang.StringIndexOutOfBoundsException: String index out of range: -1
(<Unknown source>#6) in <Unknown source> at line number 6
but can get round to it by changing line 5 to:
end = name.indexOf(".");
Cheers
Gabriel
--
ImageJ mailing list:
http://imagej.nih.gov/ij/list.html