bunwarpJ in macro headless

Hi,

I made a little macro to load and run bunwarpJ, which work like a charm. However when I try to run it in headless mode I get the following errors :

java.awt.HeadlessException
	at java.awt.GraphicsEnvironment.checkHeadless(GraphicsEnvironment.java:204)
	at java.awt.Button.<init>(Button.java:152)
	at ij.gui.GenericDialog.<init>(GenericDialog.java:101)
	at bunwarpj.MainDialog.<init>(MainDialog.java:266)
	at bunwarpj.bUnwarpJ_.run(bUnwarpJ_.java:144)
	at ij.IJ.runUserPlugIn(IJ.java:235)
	at ij.IJ.runPlugIn(IJ.java:198)
	at ij.Executer.runCommand(Executer.java:150)
	at ij.Executer.run(Executer.java:68)
	at ij.IJ.run(IJ.java:317)
	at ij.IJ.run(IJ.java:328)
	at ij.macro.Functions.doRun(Functions.java:686)
	at ij.macro.Functions.doFunction(Functions.java:98)
	at ij.macro.Interpreter.doStatement(Interpreter.java:278)
	at ij.macro.Interpreter.doStatements(Interpreter.java:264)
	at ij.macro.Interpreter.run(Interpreter.java:160)
	at ij.macro.Interpreter.run(Interpreter.java:93)
	at ij.macro.Interpreter.run(Interpreter.java:104)
	at ij.plugin.Macro_Runner.runMacro(Macro_Runner.java:161)
	at ij.plugin.Macro_Runner.runMacroFile(Macro_Runner.java:145)
	at ij.IJ.runMacroFile(IJ.java:165)
	at net.imagej.legacy.IJ1Helper$4.call(IJ1Helper.java:1165)
	at net.imagej.legacy.IJ1Helper$4.call(IJ1Helper.java:1161)
	at net.imagej.legacy.IJ1Helper.runMacroFriendly(IJ1Helper.java:1095)
	at net.imagej.legacy.IJ1Helper.runMacroFile(IJ1Helper.java:1161)
	at net.imagej.legacy.LegacyCommandline$Macro.handle(LegacyCommandline.java:185)
	at org.scijava.console.DefaultConsoleService.processArgs(DefaultConsoleService.java:99)
	at org.scijava.AbstractGateway.launch(AbstractGateway.java:103)
	at net.imagej.Main.main(Main.java:55)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at net.imagej.launcher.ClassLauncher.launch(ClassLauncher.java:279)
	at net.imagej.launcher.ClassLauncher.run(ClassLauncher.java:186)
	at net.imagej.launcher.ClassLauncher.main(ClassLauncher.java:87)

No window with the title "Registered Target Image" found.

Here is my macro :

arg = getArgument();
args = split(arg, ",");
ref_path = args[0]; // reference image
marker_path = args[1]; // image to register
ROIfile = args[2]; // landmarks in the bunwarpj format 


open(ref_path);
open(marker_path);




bunwarp_arg =  " source_image=" + File.getName(ref_path) + " target_image=" + File.getName(marker_path)+ " load=" + ROIfile +" registration=Accurate image_subsample_factor=0 initial_deformation=Coarse final_deformation=[Very Fine] divergence_weight=0 curl_weight=0 landmark_weight=1 image_weight=0 consistency_weight=10 stop_threshold=0.01"
// run registration
run("bUnwarpJ", bunwarp_arg);

selectWindow("Registered Target Image");
aligned_folder = File.getParent(ref_path);
marker_name = File.getName(marker_path);
save(aligned_folder + "/" + marker_name);

Is bunwarpJ incompatible with headless mode ? Should I rather use the command line version ?
I tried to add a waiting time just to be sure that the selectwindow command didn’t run before bunwarpj is done but this don’t seem to be the issue.

Thank you for your help !