How to create a message prompt/dialog for directory selection

I have the following script that ask users for input and output directory
in that order:

from ij import IJ, ImagePlus
#Set input directory...
srcDir = IJ.getDirectory("Input_directory")
#Set output directory...
dstDir = IJ.getDirectory("Output_directory")
print "Source directory: ", srcDir
print "Destination directory: ", dstDir

What I want to do is before showing up the directory windows, I’d like a
message prompt to tell user that he should be choosing source or target directory.
How can I do that?

If you really want a prompt that only shows a message you can use IJ.showMessage(). There is also a lot of other static helper methods in the IJ class, so you should take some time look at the JavaDoc and maybe as well at the Jython scripting page.

Additionally, you should consider using Script Parameters for user input. They can have descriptive labels, which might render your message dialog unnecessary:

# @File(label='Source directory', style="directory") srcDir
# @File(label='Destination directory', style="directory") dstDir

from ij import IJ, ImagePlus

print "Source directory: ", srcDir
print "Destination directory: ", dstDir

This way, you can also pass the parameters in headless mode from the commandline without a hassle.

Best,
Stefan

2 Likes