Changes in the panel bar

Hi All,

I wrote some scripts for imageJ for my usage, is there any way to add them to the line in the ain panel bar of imageJ so the I have a better access?

Thanks in advance


Hi @microb1,

this is how you can add a menu icon on top via the More Tools menu >>
Save the following macro under ►macros ►toolsets and it will appear in the More Tools menu

var filemenu = newMenu("My Awsome Menu Tool", newArray("my first tool", "my second tool", "-", "the ultimate uber tool"));

macro "My Awsome Menu Tool - CfffL0060CffdL7080CffeD90CfffLa0f0CffeL0111CfffD21CffeD31CffcD41CffdD51CffcD61CeeaD71Cbb4D81Cbc5D91Cdd9Da1CeebDb1CfffLc1f1CdeaD02Cdd7D12CffbD22CffaD32Ccc6D42Cab4L5262Cdd8D72C891D82C780D92C9a2Da2C8a2Db2CeeaDc2CfffLd2f2CeecD03Ccc7D13Ccc5D23Cdd7D33Cdd8D43C891D53C780D63Cbc5D73Cab4D83C790L93b3Cbb5Dc3CffcDd3CfffLe3f3CffeD04CeeaD14Cdd7D24C9a3D34Cab3D44C9a2D54C780D64C9a2D74Cab4D84C791D94C780Da4C790Db4C892Dc4Cab4Dd4CffeDe4CfffDf4D05CeeaD15C9a2D25C891D35C790L4555C780L6575C891D85C681D95C680Da5C780Lb5c5C891Dd5CdebDe5CfffDf5D06CeebD16Cab4D26C780L3656C680L6676C780L8696C681Da6C680Lb6c6C791Dd6Ccc7De6CffeDf6CfffD07CffdD17Cbc5D27C780L3757C790D67C780L77a7C680Db7C780Dc7C791Dd7C891De7CdebDf7CfffD08CffeD18Ccc7D28C9a2D38C780L4858C680L6888C670D98C680La8b8C780Dc8C791Dd8C891De8Ccc8Df8CfffD09CeecD19Ccc7D29C9a2D39C780D49C790L5969C780D79C680D89C780D99C680La9d9C780De9CccaDf9CfffD0aCeecD1aCab3D2aC780L3a5aC680D6aC780L7aaaC680LbacaC780DdaCab5DeaCffeDfaCfffD0bCffeD1bCbc5D2bC891D3bC790L4b5bC791D6bC781D7bC680L8bbbC670DcbC782DdbCeedDebCfffDfbL0c1cCddaD2cC891D3cC790L4c5cC780L6c7cC791D8cC780L9cbcC892DccCbb8DdcCcc9DecCcdaDfcCfffL0d2dCcdaD3dC9a2D4dC790D5dC890D6dC891D7dC781D8dC780D9dC891LadbdCcdaDcdCfffDddCffeDedCeedDfdCfffL0e3eCddbD4eC9a4D5eC681D6eC782D7eC8a2D8eC892D9eC9a5DaeCcdbDbeCfffLcefeL0f5fCddcD6fCcdbL7f8fCdedD9fCfffLafff" {
	menuCommand = getArgument();
	if(menuCommand!="-") {
		if(menuCommand=="my first tool") {
			print("you pressed the first menu item");
		} else if(menuCommand=="my second tool") {
			print("you pressed the second menu item");
		} else if(menuCommand=="the ultimate uber tool") {
			print("you pressed the ultimate uber tool menu item");

You can also add it to the autostart, that it will always be loaded when you start Fiji/IJ
Therefore, you will need to edit the ►macros ►StartupMacros.fiji.ijm file

You can add or adapt the following:

macro "AutoRun" {
	// run all the .ijm scripts provided in macros/AutoRun/
	autoRunDirectory = getDirectory("imagej") + "/macros/AutoRun/";
	if (File.isDirectory(autoRunDirectory)) {
		list = getFileList(autoRunDirectory);
		// make sure startup order is consistent
		for (i = 0; i < list.length; i++) {
			if (endsWith(list[i], ".ijm")) {
				runMacro(autoRunDirectory + list[i]);
	path = getDirectory("macros");
	run("Install...", "install=["+path+File.separator+"toolsets"+File.separator+"My Tools Menu Name.ijm]");

I haven’t tested the last part now and just copied it from my custom menues but it should work.

first of all thank you for your help,
actually I have a bit problem because I am triyng to add a script which is writen as python here is example:

#@ String(Label="Size of image") W
# Create new ROI programmatically
from ij import IJ
from ij.gui import OvalRoi, Roi
# Get current ImagePlus
image = IJ.getImage()
# Enter ROI coordinates
width = size
height = size
x_ROI = 100 # ROI center
y_ROI = 100 # ROI center
oval = False # Set to True to get an oval ROI
# Make it
x1 = int(x_ROI - (width/2))
y1 = int(y_ROI - (height/2))
if oval:
  roi = OvalRoi(x1, y1, width, height);
  roi = Roi(x1, y1, width, height);

And I couldn’t do it in this case I got the following error:

DO you know how I can solve this problem please?
Thanks in advance,

You can save your script and then call it via the code I posted above by including one of the commands mentioned in the Built-in macro functions page

Runs the specified macro or script, which is assumed to be in the Image macros folder. A full file path may also be used. Returns any string argument returned by the macro or the last expression evaluated in the script. For an example, see the CalculateMean macro. See also: eval.

runMacro(name, arg)
Runs the specified macro or script, which is assumed to be in the macros folder, or use a full file path. The string argument ‘arg’ can be retrieved by the macro or script using the getArgument() function. Returns the string argument returned by the macro or the last expression evaluated in the script. See also: getArgument.

Thanks again’ I tried to do what you recomend but I got this error message:

I geuss that it’s because I cannot get the parameters of the script like “W”, is there any other way
to run the script of the python because in general I need to choose a number in order to run the script?

Hmmm :thinking: strange. I can reproduce that error but honestly do not have a solution for it.
Potentially @imagejan, @haesleinhuepf might have an answer to this issue.

Add on: I tested this by calling a macro file via runMacro(path) and received as well an error but only if the macro started with a scripting parameter definition (e.g. //@String(label="blahblah") inputText).
If I change this to the older/normal command word = getString("key in a word", "default"); then it works as expected and I can start the macro from another one. So this might have to do with the way IJ calls a script or a macro which starts with a scripting parameter.

You might want to test this by adding to your script also a standard call for the variable “W” instead of the scripting parameter, just to see, if that would as well solve the issue.

@ctrueden is that something you would expect to happen for some reason I am unaware of or rather a scripting parameter related issue when calling a macro from a file?

1 Like

Actually, I exchanged in your python script the scripting parameter definition and added W = IJ.getString("key in W", "") after the import statements and then it seems to work.
So, it is definitely related to the scripting parameter input definition.

1 Like

The runMacro command calls the ImageJ1 macro interpreter directly and therefore doesn’t support SciJava script parameters (which are an ImageJ2/SciJava feature).

It could be made to work by re-writing the macro command within the imagej-legacy layer (feel free to open an issue here), but I’m not sure if it’s worth the effort, given you can work around the issue as follows:

  • Save your script in a subdirectory of ./, e.g. ./, so that it appears in the menus.

  • Call it using run instead of runMacro:

    run("My Awesome Script");