Distribute macro associated to a keyboard shortcut

I really like the option to associate a keyboard shortcut to a macro with the simple square bracket mechanism.
Like

macro "MyMacro [1]" {
    print("The user pressed '1'");
    }

I have seen 3 options to have the shortcut functional in ImageJ/Fiji:

  • Put the macro code in the StartupMacro.txt
  • Save the macro in the plugin folder so that it appears in the menu and then you can set a keyboard shortcut to the menu (yet not using the square bracket mechanism)
  • Run Plugins>Macro>Install...

However none of them really convince me, especially if say I want to distribute a macro via an update site and the shortcut should work right after activating the update site.

Is there another solution that I missed ?

Otherwise I was thinking of adding a small script in scripts>plugins>autorun that would call the MacroInstaller for every macro file in a specific subfolder of e.g Fiji.app/macros at startup.
So some kind of automated version of point 3 above.

Hi @LThomas!

You can also put it (or a helper/loader script) in the macros/Autorun/ folder.
I have been playing with this option for custom macro functions, although I haven’t added this as an update site (yet :grin:).

If you distribute it using an update site, this user is expected to restart Fiji, so any of the autorun options should be ok.

I’d like to see what others can add in this regard, as this is always an interesting topic.

Cheers!
Nico

1 Like

Hi Nico,
Thanks for the tips,
I tried putting a macro file in the macros/Autorun folder but unfortunately this does not work.

I tried the option with a helper file to install a set of macro file automatically at startup using a helper script that calls the Plugins>Macro>install command. Surprisingly only the last installed macro is actually visible and activated in the menu. Even if you do it manually via the menu, the newly installed command replaces the previously installed one. So kind of limiting.

However I found a solution for my problem (having keyboard shortcuts calling custom macros automatically available) : the macros defining shortcuts can be saved as a macro toolset (ijm or txt) in the macros/toolsets subfolder.
You can they “activate” the shortcuts by clicking the >> at the rightmost side of the toolbar and click the toolset of interest. This will install the macros contained in the toolset and thus activate their shortcut.

This option is great if you want to distribute keyboard shortcut via an update site !

1 Like