Running plugin from within script



Can someone help me run a plugin from within my script?

I have been trying to write a script that would use the ‘wound healing image tool’ (link to the plugin). I’m trying to write the script below to save the area calculations in separate csv files, and the processed image separately, for me to review before processing it in R.

I cannot figure out what is needed to run the ‘measure wound healing tool’ option through a script instead of having to click the toolbar button. Could you help me?

input = getDirectory("Input Directory");
output = getDirectory("Output Directory");

list = getFileList(input);
for (i = 0; i < list.length; i++) {
    action(input, output, list[i]);

run("Install...", "install=[D:/Dropbox/work/imaging/Fiji macro/MRI_Wound_Healing_Tool.ijm]");	

//  Start of program

function action(input, output, image) {

// To Run the wound healing measuring macro 
   macro 'Measure Wound Healing Action Tool Options' {
     Dialog.create("Wound Healing Tool Options");
     Dialog.addChoice("method", methods, method);
     Dialog.addNumber("variance filter radius", varianceFilterRadius);
     Dialog.addNumber("threshold", threshold);
     Dialog.addNumber("radius open", radiusOpen);
     Dialog.addNumber("min. size", minSize);
     Dialog.addCheckbox("ignore spatial calibration", measureInPixelUnits);;
     method = Dialog.getChoice();
     varianceFilterRadius= Dialog.getNumber();
     threshold= Dialog.getNumber();
     radiusOpen = Dialog.getNumber();
     minSize = Dialog.getNumber();
     measureInPixelUnits = Dialog.getCheckbox();

// To save results
	// saveAs("Results",  output + yourFileName + ".csv"); 
	// saveAs("Results")
	selectWindow("ROI Manager")

// To close previously opened windows.
    selectWindow("ROI Manager");


Good day!

I have been trying to write a script that would use the ‘wound healing image tool’ (link to the plugin).

“MRI_Wound_Healing_Tool.ijm” is an ImageJ-macro (actually it is a Tool Set) not an ImageJ-plugin!

What you are trying to write is not a script but an ImageJ-macro.

Please make sure of how to call a macro from a macro.




Hi @agenttiny120,

in case you want to call one macro from another, use the runMacro() method. Here are two example macros doing this:

macro1.ijm :

IJ.log("Hello world, I'm macro1");



IJ.log("Hello world, I'm macro2");

If you run macro1 (make sure to adapt the path of macro2) , it will output something like:

I hope that helps!





is actually Java-speak but apparently it works in a macro as well.

Usually “print()” outputs from a macro to the log-window.




woops, I got confused when trying to understand the wound healing code…


It seems as though it worked, i’m getting error messages now from the ‘saveas()’ lines now. I think its having trouble recognizing the results window. there’s bound to be a post about that somewhere


We’re happy to help, but please tell us the error message and show us the code producing it :wink:


Indeed, IJ.log is a supported macro function, please consult the documentation:


Yes Jan,

you are right and I’ve admitted this to Robert who preferred to communicate off-Forum. I forgot to mention it on the Forum afterwards.

I think the macro call


is redundant though.

Thanks for the remark



I think i know the problem…when I comment out the ‘saveAs’ part of the script, the response is always that it can’t find the ‘Results’ or ‘ROI Manager’ Window. I don’t think the wound healing macro can be called by runMacro, because the ‘MRI_Wound_Healing_Tool.ijm’ is designed to add two macros to the toolbar.

I believe i know the problem and need some advice. the wound healing ijm adds two buttons/macros to the toolbar: one is a help option, and the other runs the actual wound healing tool. How can I either

(a) run specifically this button/macro through my script, along with functions and variables stated in ‘MRI_Wound_Healing_Tool.ijm’? I cannot determine the necessary code through ‘record macro’ and pressing the tool button (nothing shows up in the recording).


(b) copy and paste the macro, variables, and functions, into my script to be called on demand? I don’t fully understand what is necessary to call a macro within a script.

I have attempted both methods with limited success. The exact part of the wound healing script that I believe I need are as follows:

var helpURL = ""
var varianceFilterRadius = 10;
var threshold = 50;
var radiusOpen = 4;
var minSize = 10000;
var methods = newArray("variance", "find edges");
var method = "variance";
var measureInPixelUnits = false;

macro "Unused Tool - C037" { }

macro "MRI Wound Healing Tool Help Action Tool - C000C111C222D07D08D09D0aD0bD0cD0dD0eD0fD18D19D1aD1bD1cD1dD1eD1fD28D29D2cD2dD2eD2fD38D39D3aD3bD3cD3eD3fD40D49D4aD4bD4cD4dD4eD4fD50D51D52D5aD5bD5cD5dD5eD5fD60D61D62D6aD6bD6cD6dD6eD6fD70D71D72D73D7bD7cD7eD7fD80D81D82D83D8cD8dD8eD8fD90D91D93D94D9cD9dD9eD9fDa0Da1Da2Da3Da4DadDaeDafDb0Db1Db2Db3Db4Db5DbeDbfDc0Dc1Dc2Dc4Dc5DcfDd0Dd2Dd4Dd5DdfDe0De2De3De4De5DefDf0Df1Df2Df3Df4Df5Df6C222C333C444C555C666C777C888C999D2aD2bD3dD7dD92Dc3Dd1Dd3De1C999CaaaCbbbCcccCdddCeeeD00D01D02D03D04D05D06D10D11D12D13D14D15D16D17D20D21D22D23D24D25D26D27D30D31D32D33D34D35D36D37D41D42D43D44D45D46D47D48D53D54D55D56D57D58D59D63D64D65D66D67D68D69D74D75D76D77D78D79D7aD84D85D86D87D88D89D8aD8bD95D96D97D98D99D9aD9bDa5Da6Da7Da8Da9DaaDabDacDb6Db7Db8Db9DbaDbbDbcDbdDc6Dc7Dc8Dc9DcaDcbDccDcdDceDd6Dd7Dd8Dd9DdaDdbDdcDddDdeDe6De7De8De9DeaDebDecDedDeeDf7Df8Df9DfaDfbDfcDfdDfeDff"{
    run('URL...', 'url='+helpURL);

macro 'Measure Wound Healing Action Tool - C000T4b12m' {
	run("Select None");
	getPixelSize(unit, pixelWidth, pixelHeight);
	run("Duplicate...", "duplicate");
    setForegroundColor(0, 0, 0);
    setBackgroundColor(255, 255, 255);
    roiManager("Associate", "true");
    if (method=="variance") 
    run("Convert to Mask", " black");
    run("Invert", "stack");
    for (i=0; i<radiusOpen; i++) {
        run("Dilate", "stack");
    for (i=0; i<radiusOpen; i++) {
        run("Erode", "stack");
    run("Select All");
    run("Enlarge...", "enlarge=-" + radiusOpen + " pixel");
    run("Invert", "stack");
    run("Analyze Particles...", "size="+minSize+"-Infinity circularity=0.00-1.00 show=Nothing add stack");
    run("Clear Results");
    if (measureInPixelUnits)
    		run("Set Scale...", "distance=0 known=0 pixel=1 unit=pixel");
    roiManager("Show None");
	roiManager("Show All");

function thresholdVariance() {
    run("Variance...", "radius=" + varianceFilterRadius + " stack");

function thresholdFindEdges() {
    run("Find Edges", "stack");
    run("Invert", "stack");
    setAutoThreshold("Percentile dark");


Good day!

I don’t think the wound healing macro can be called by runMacro , because the ‘MRI_Wound_Healing_Tool.ijm’ is designed to add two macros to the toolbar.

That’s why I wrote in my first post:

“MRI_Wound_Healing_Tool.ijm” is an ImageJ-macro (actually it is a Tool Set) not an ImageJ-plugin!

It is a “Tool Set” and as such the approach Robert has suggested isn’t feasible, at least not as easy.

What you need to do is have a look at the macro code and use/call the parts you need.




My apologies, I didn’t understand what you meant with my ijm programming knowledge at the time. I’ve found some documentation on running macros within macros, I’ll try those out and let you guys know how it goes!