Run an ImageJ macro directly from GitHub Gist | Adam Dimech's Coding Blog
Skip to content

Run an ImageJ macro directly from GitHub Gist

G23rd May 2018

CNo Comments

TGit, ImageJ

Simple code that enables you to host your ImageJ macro scripts on GitHub Gist but execute them from a local machine.

When developing ImageJ macro scripts, I like to back-up my code on GitHub Gist. Aside from securing my backups, GitHub enables me to distribute code amongst my colleagues and update that code remotely without the need to individually update scripts via a fresh installation on each instance of ImageJ that my work group uses.

Running an ImageJ macro script hosted on GitHub Gist

It is entirely possible to use ImageJ on a PC to execute .ijm files hosted on GitHub Gist. Here’s how to do it:

Let’s say that a useful Image J macro script has been saved to https://gist.github.com/AdamDimech/66391d775d0d602a207b4dfc41e8556e. To execute this code, the raw-formatted version needs to be accessed, which is a simple case of adding /raw to the end of the URL. (You will notice that gist.github.com redirects to gist.githubusercontent.com when raw files are accessed).

The raw file URL can be wrapped in code and executed as a macro in ImageJ as follows:

macro "Time String" {
macrotext = File.openUrlAsString("https://gist.githubusercontent.com/AdamDimech/66391d775d0d602a207b4dfc41e8556e/raw/");
eval(macrotext);
}

Save this text in an .ijm plain-text file. Note: ImageJ requires that the .ijm file must have an underscore in its name (eg: time_stamp.ijm).

This ImageJ macro code tells ImageJ to read the contents of the website and run that script using eval(). Accessing code from any other website would be equally possible as long as the code is provided as plain text and not formatted HTML.

To test the code in ImageJ, go to File > New > Script and paste the above code into the editor. In the menu, go to Language > IJ1 Macro, then press “Run” to test.

Screen capture of the ImageJ macro editor.

The ImageJ code editor can be used to test ImageJ macro scripts.

Installing your macro into ImageJ

If you are running the Fiji version of ImageJ and would like to create a menu in ImageJ to access the macro, go to the folder path at C:\Your\Path\To\ImageJ\fiji-win64\Fiji.app\scripts\Plugins. Create a new sub-folder under \Plugins and save your .ijm file there.

For instance, you might create a folder called \Plugins\Time Stamp\ and then save the file time_stamp.ijm into that.

Restart ImageJ and you should be able to access your macro via Plugins > Time Stamp > Time Stamp in the ImageJ menu.

Any updates that are made to the script file on GitHub Gist will be implemented when the script is run on ImageJ.

   

Comments:

No comments have yet been submitted. Be the first!

Have your say:

The following HTML is permitted:
<a href="" title=""> <b> <blockquote cite=""> <code> <em> <i> <q cite=""> <strike> <strong>

Comments will be published subject to the Editorial Policy.