Get the folder from which a script is running?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Get the folder from which a script is running?

lechristophe
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)?

Thanks!

Christophe

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

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

Rasband, Wayne (NIH/NIMH) [E]
> 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
Reply | Threaded
Open this post in threaded view
|

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

Gabriel Landini
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