Posted by
Jeff Brandenburg on
Aug 16, 2005; 7:21pm
URL: http://imagej.273.s1.nabble.com/Auto-launching-macros-was-Re-startup-tp3705027p3705029.html
On Jul 13, 2005, at 2:34 PM, Jeff Brandenburg wrote:
> On Jul 12, 2005, at 1:06 PM, Wayne Rasband wrote:
> > Macros named "AutoRun" execute automatically when they are opened or
> > installed. For example, the macro
> >
> > macro "AutoRun" {
> > run("Close"); // close text window
> > print("This macro automatically runs when it is opened");
> > }
> >
> > executes when you open it using File>Open or drag and drop it on
> > ImageJ. The run("Close") statement closes the text window that is
> > opened when you open a macro file.
>
> Brilliant! This is exactly what I need. Thanks, Wayne!
...well, it was *almost* exactly what I need. :-)
I'm generating macro scripts, serving them up from a Tomcat web app,
and using ImageJ as a helper app to execute them. Here's an example:
macro "AutoRun" {
run("Close");
run("CIVM Web Stack Opener", "runno=S22023 startcount=1 endcount=2048
cookie=JSESSIONID=30CB71F2F41F50B65985BD4BC98C0127");
}
I serve this up with a Content-disposition: header that puts it into a
file named <runno>_browse.txt -- in this case, S22023_browse.txt . The
macro autoexecutes, but you can also rerun it later by dropping it onto
ImageJ.
My problem: every once in a while (I haven't been able to narrow it
down any more than that), the run("Close") statement closes the wrong
window. Sometimes, it appears to close the newly-opened stack window,
which certainly shouldn't happen (since that window gets created AFTER
the close command). Sometimes, it closes another stack window, which
is a nuisance when I'm trying to compare several stacks.
I tried adding a selectWindow() statement:
macro "AutoRun" {
selectWindow("S22023_browse.txt");
run("Close");
run("CIVM Web Stack Opener", "runno=S22023 startcount=1 endcount=2048
cookie=JSESSIONID=30CB71F2F41F50B65985BD4BC98C0127");
}
This works sometimes. However, if I browse the same volume more than
once, the browser saves subsequent macro files as S22023_browse-1.txt,
S22023_browse-2.txt, and so on. There's no convenient way for me to
tell when this is happening from the server side, so I'm not sure what
I can do about it. I suppose I could add a random or serial key to the
filename to avoid duplicates, but I'd rather not.
Does anybody recognize what's going on here? Is it a race condition?
Is there something simple I can add to the script to avoid it? Or am I
doing something obviously and fixably wrong?
Thanks...
--
-jeffB (Jeff Brandenburg, Duke Center for In-Vivo Microscopy)