Install a macro with a macro

Dear helpers,

I wrote a macro and saved it with an underscore in the FiJi plugin directory. So one can now run the macro by clickin on it.
This macro contains shortcuts defined by me for example macro "Dentininterface [2]" { waitForUser(" . If I want to use these shortcuts I need to install the macro. But I dont want to install it manualy every time I use it. Therefore I used the macro recorder, installed it and pasted the code to my macro.
I want to run this marco from different machines so I figured if I use the getDirectory("imagej"); command I can make this code variable.

But if I run the following code ImageJ displays me following message: Filename must end with “.txt” or “.ijm”.

j = getDirectory("imagej");
k=j+"plugins\\OCT Uni Leipzig\\";
n=replace(o, "\\","/");
m=replace(n, "/","//");
p=replace(m,"//", "\\\\\\\\");
print("p =",p);
run("Install...", "install=p");

I don’t know if the replacement is necessary. But with it, the path “p” looks almost like the orginal recorded version.
One thing is different, maybe thats the reaseon why it won’t work. Fiji is “installed” on my desktop. so the path looks like “C:\Users\Username\” but instead of Username it is "\Userna~1\.

Can you help me?

Best regards


Dear Tobias,

I have the following InstallMacros.ijm in the macros/AutoRun/ folder of my Fiji installation:

macrosDirectory = getDirectory("macros");
run("Install...", "install="+macrosDirectory+"toolsets"+File.separator+"xyz.ijm");

Due to its location, this macro will be executed automatically on startup of Fiji and, thus, installs macros/toolsets/xyz.ijm of the currently running Fiji instance’s folder.

I hope that solves your problem…

All the best,

1 Like

Dear Stefan,

thanks for your reply. I know that feauture of ImageJ and I’m using it with some other macros I wrote. :slightly_smiling:
But I dont really wan’t to install this macro every time Imagej starts. I just want to install it when the macro is used (because of the modefied shortcus, which overwrite existing ones)



You have a quoting error here where your variable name is included in the literal string “install=p”… see if this fixes it:

run("Install...", "install="+p);



Thanks Mark,

this fixed it.:smile: