Auto-launching macros (was Re: startup)

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Auto-launching macros (was Re: startup)

Jeff Brandenburg
I have a problem similar to Charlotte Holmes'.  I'd like to be able to
open a macro and have it execute automatically, without the "Run" command.

It's my understanding that I can create a macro named StartupMacro.txt,
put it into the macros folder, and have it execute automatically when
ImageJ starts.  That's not quite what I want.  Instead, I'd like to be
able to drag and drop a macro onto ImageJ -- actually, download a macro
file from a Web server, then use ImageJ as the helper app to open it --
and have it run automatically, without requiring the user to issue a
"Run" command.  ImageJ may already be running when I try to open this
macro, and so I can't make direct use of the StartupMacro facility.

I want to use the locally-installed copy of ImageJ on a client machine
to view data hosted on a remote server.  To that end, I'll be running a
modified version of Virtual Stack Opener, which I'll require my users to
install.  I *could* also require my users to install a special startup
macro that installs a modified Opener, one that recognizes a special
macro format and automatically executes it, but that's kind of invasive.
  (For that matter, I could just make them install a modified version of
ImageJ, but I'd really prefer to stick with the standard version.)

Has anyone else already solved this problem?

Thanks!
--
        -jeffB (Jeff Brandenburg, Duke Center for In-Vivo Microscopy)
Reply | Threaded
Open this post in threaded view
|

Re: Auto-launching macros (was Re: startup)

Wayne Rasband
> I have a problem similar to Charlotte Holmes'.  I'd like to
> be able to open a macro and have it execute automatically,
> without the "Run" command.

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.

> It's my understanding that I can create a macro named
> StartupMacro.txt, put it into the macros folder, and have it
> execute automatically when ImageJ starts.

If you have a macro named "AutoRun" in StartupMacro.txt then it will
run automatically when ImageJ starts.

-wayne
Reply | Threaded
Open this post in threaded view
|

Re: Auto-launching macros (was Re: startup)

Jeff Brandenburg
In reply to this post by Jeff Brandenburg
On Jul 12, 2005, at 1:06 PM, Wayne Rasband wrote:

 > > I have a problem similar to Charlotte Holmes'.  I'd like to
 > > be able to open a macro and have it execute automatically,
 > > without the "Run" command.
 >
 > 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!
--
        -jeffB (Jeff Brandenburg, Duke Center for In-Vivo Microscopy)
Reply | Threaded
Open this post in threaded view
|

Re: Auto-launching macros (was Re: startup)

Jeff Brandenburg
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)