Does anyone have an elegant way to ID the folder a macro is run from?



I develop macros for users and I send them interim versions with data (images) in a folder. The folder is at a completely different path once it lands on their computer, so I can’t embed paths in the open() command that will work on their computer. Has someone figured out a way to ID the folder from which a macro is run. The macro may be run by dragging it to IJ, or by double clicking it in the Win10 file system once .ijm is associated with IJ, however a macro has no reference from which folder it came, so any images opened can’t be found. I’m adding a simple macro in the folder to be run first that contains the single command <getDirectory(“Choose The Downloaded Directory”);> which asks the user to select the folder where the data and main macro are. This is clunky, but I don’t want the user to have to ID the folder each time he/she runs the main macro by putting the same command in the algorithmic macro. IJ remembers which directory it last opened an image from, but does not do the same for macros, so opening an image from the folder first will accomplish what’s needed, but I would like the user to be able to just double click the macro and have it open the images in the same folder.
Has any one figured out how to ID a folder from which a macro has been run?

Folder of the current macro

Upgrade to the latest ImageJ daily build (1.51s30) and you can use the macro function to get the path to the folder that a macro is run from.


Thanks Wayne works when the .ijm is dragged onto IJ and run in the editor, but not when the macro is double clicked on the desktop.

Ron DeSpain


Hi Ron,

Are you sure you are running ImageJ 1.51s30 or later? I get this output

dir: C:\Users\rasba\Downloads\
name: ShowInfo.ijm
version: 1.51s30
os: Windows 10 10.0`

when I double click on this macro:

  print("dir: ";
  print("name: ";
  print("version: "+IJ.getFullVersion);
  print("os: "+getInfo("")+" "+getInfo("os.version"));


I get this output

version: 1.51r17
os: Windows NT (unknown) 6.2

…I’m running Win 10

When I select update I get this: "Error opening"
Does this have something to do with ImageJ2…which I haven’t looked into yet.


Hi Ron,

You need to be running ImageJ 1.51s30 or later. The error has nothing to do with ImageJ2. You might try downloading the ImageJ distribution for Windows bundled with with 64-bit Java 1.8.0_112, available at, and using the Help>Update ImageJ command to update to the daily build.


I got the update and now the macro returns.

dir: C:\Users\User\Desktop\double click problem
name: ShowInfo.ijm
version: 1.51s30
os: Windows NT (unknown) 6.2

any idea why the os is NT?

Double click now works…thanks.


The getInfo(“”) function (System.getProperty(“”) method) returns “Windows NT” when running Java 6 on Windows 10.