Login  Register

Re: installing macro properly?

Posted by Curtis Rueden-2 on Jun 10, 2020; 10:42pm
URL: http://imagej.273.s1.nabble.com/installing-macro-properly-tp5023470p5023484.html

Hi all,

Kenneth Sloan wrote:
> I really did like keeping all of my plugins in a separate
plugins/subFolder.

ImageJ2 (and therefore Fiji) lets you put macros and scripts wherever you
want in the menus, including nested submenus. Just place your scripts in a
subfolder of scripts/. (For backwards compatibility with previous behavior,
it also works to use plugins/Scripts/ or plugins/, although I would not
recommend doing this.)

Alternately, you can embed them into a JAR file at a path like
/scripts/Toplevel_Menu>/Optional_Submenu/Optional_Nested_Submenus_Etc/My_Script.js,
with the JAR file itself living in the jars/ directory as usual. Here is an
example embedded script:

https://github.com/imagej/imagej-legacy/blob/imagej-legacy-0.37.4/src/main/resources/scripts/Image/Adjust/Manual_Threshold....js

Use a file extension matching one of the supported script languages; for
ImageJ macros, that is .ijm.

Wayne Rasband wrote:
> with Fiji, the macro must have an underscore in the name

To test this, I created the following files in my local Fiji installation:
  ./scripts/Foo/Bar_Bar.ijm
  ./scripts/Foo/Bar.ijm
  ./plugins/Scripts/Foo2/Bar2_Bar2.ijm
  ./plugins/Scripts/Foo2/Bar2.ijm
  ./plugins/Foo3/Bar3.ijm
  ./plugins/Foo3/Bar3_Bar3.ijm

When I type 'bar' into the search bar, all six items appear as entries.
However, only the three items with underscores actually appear in the
menus, at the following locations:
  ./scripts/Foo/Bar_Bar.ijm -> Foo > Bar Bar
  ./plugins/Scripts/Foo2/Bar2_Bar2.ijm -> Foo2 > Bar2 Bar2
  ./plugins/Foo3/Bar3_Bar3.ijm -> Plugins > Foo3 > Bar3 Bar3

The reason that scripts without underscores are not included is due to this
line of code:

https://github.com/imagej/imagej-legacy/blob/imagej-legacy-0.37.4/src/main/java/net/imagej/legacy/LegacyService.java#L682

Which was added in this commit:

https://github.com/imagej/imagej-legacy/commit/1edf9f4ca4f58a080f1a783da998ef0818ecbd86

In response to this bug report:
  https://fiji.sc/bug/804.html

I'm sure there is a more elegant solution to avoid spurious script entries
while still allowing valid scripts without underscores to be discovered,
but I don't have time to think about it right now. Pull requests are
welcome (as long as they are well tested!).

Regards,
Curtis

--
Curtis Rueden
Software architect, LOCI/Eliceiri lab - https://loci.wisc.edu/software
ImageJ2 lead, Fiji maintainer - https://imagej.net/User:Rueden
Have you tried the Image.sc Forum? https://forum.image.sc/



On Wed, Jun 10, 2020 at 2:43 PM Kenneth Sloan <[hidden email]>
wrote:

> Wayne-
>
> Thanks for the prompt reply.
>
> I am using FIJI, and tried your suggestion to use Install instead of
> Install Plugin.
>
> That seemed to work as you described, but also (as I think you described),
> the plugin is not visible in any menu.
>
> Is this a limitation for FIJI?  If so, I suppose I can live with it, but I
> really did like keeping all of my plugins in a separate plugins/subFolder.
>
> Using Install... and putting foo_macro.ijm in plugins, the macro is
> installed, and works - but it still shows up at the bottom of the Plugins
> menu. So, it is accessible as:
>
> Plugins>foo_macro
>
> Is there any way to make it appear in the menu as:
>
> Plugins>subMenu>foo_macro?
>
> The macro is written (as demonstrated by the example macro) as:
>
> macro "<subMenu> foo_macro" { ... stuff ... }
>
> but the <subMenu> seems to have zero effect.
>
> Is this another difference between ImageJ and FIJI?
>
> Is there another mechanism I can use to create Plugins>subMenu and install
> macros so they appear there?
>
> I realize that this is largely cosmetic, but I'm trying to understand how
> this all works.  Both the location of the macro (in a separate
> plugins/subFolder) and the appearance on the menu (at Plugins>subMenu) are
> things I would *like* to do - but neither are critical.
>
> Recall that my standard practice in the past was to install .jar files
> containing both Java classes and a "plugins.config" file.  That's the only
> mechanism I currently understand for manipulating the appearance of the
> menu structure.  Is there particular piece of documentation (for either
> ImageJ or FIJI - but FIJI is what we are using) which explains this?
>
> Hmmm...would it work to package foo_macro.ijm and a plugins.config file in
> a .jar file and try to install *that*?  Would this work in FIJI, if the
> .jar file were in plugins>subFolder?  Is there some *other* recommended
> place to install macros so that access to them looks just like access to
> Java plugins?
>
> Of course, if push came to shove, I could just take the macro and rewrite
> it in Java.  Perhaps that would be easier, all around.
>
> --
> Kenneth Sloan
> [hidden email]
> Vision is the art of seeing what is invisible to others.
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

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