Login  Register

Re: Get the folder from which a script is running?

Posted by Rasband, Wayne (NIH/NIMH) [E] on Jun 22, 2015; 9:30pm
URL: http://imagej.273.s1.nabble.com/Get-the-folder-from-which-a-script-is-running-tp5013224p5013249.html

> On Jun 20, 2015, at 3:41 PM, Christophe Leterrier <[hidden email]> wrote:
>
> Hi,
>
> Is there a way for an ImageJ javascript to report from which folder it
> running (i.e. the path to the js file or to its parent folder)?

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));

returns

   folder=Tools

-wayne
--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html