It is reversed problem to:
How can I call/execute a java program from an ImageJ macro?
Whenever I write imagej I refer to fiji.
Of course a trivial solution is to create a .ijm from java string and call imagej using a system call with .ijm as an argument, but I search for better solution. Alternatively .ijm instructions can be translated into java calls but it is not very convenient (when .jvm is enough for the job it is very convenient way to keep it in this format).
Why is it useful? It can be used e.g. to distribute a .ijm macro in obfuscated way - make it more difficult to the user to extract the macro. String containing instructions for .ijm can be decrypted only when correct password is provided, etc. Thank you for any suggestions!
Use the
ij.IJ.runMacro(String)
method.Here is an example:
A word of warning about obfuscation, though: Java is notoriously easy to decompile.
Correct me if I am wrong but one could call IJ.runMacroFile to refer to a given macro text file in the macro folder.
Yet I don't know if you can run macros outside of the macro folders, for example from within a .jar