Stop a running macro

Hi everybody,

I have a macro which is launched on all pictures in a folder.
Sometimes, there is a lot of picture in a folder and i would like to allow users to stop the running macro by pressing a key or clicking on a button.

If someone has an idea about how make this possible, i would really appreciate to know his/her method !

Thanks a lot,
Kévin.

See here:

http://imagej.1557.x6.nabble.com/kill-a-thread-macro-or-plugin-td3695966.html

Hello,

thanks for your answer. I tried your solution but i still have a problem :

I use two macros , A and B , like this :

Macro A {
For each picture in folder : call macro B
}
So when i press escape, it only stop the current macro B, but not the Macro A, so the macro A start the macro B again on the next picture.

Thank you,
Kévin.

Try to use “isKeyDown”

something like:

for (i = 0; i < 100; i++) {
    interruptMacro = isKeyDown("space");
    if (interruptMacro == true) {
        print("interrupted");
        setKeyDown("none");
        break;
    }
    print(i);
    wait(500);
}

The log window can receive the key events if you have problems with the key listener.

3 Likes

Thanks a lot four your help ! That’s seems a great idea, i will try to adjust it for my code !

Kévin.

just to add my personal thank you, very nice suggestion!

have a nice day,
Emanuele