It
should be possible to run a script from the command line.... although I'm not entirely sure whether it is.
You can see hints of it in the code
here.
From within the directory containing QuPathApp.jar, you would use
java -jar QuPathApp.jar /path/to/image/or/qupdata/file -script /path/to/script
It is a long time since I ever used this though, so I'm not sure if it still works. It doesn't appear to use the same automatic imports that are applied in the script editor by default; meaning that, if required, you'd need to handle any of these (e.g. qupath.lib.scripting.QP) within the script; see this for some more information.
Writing a Java program would be an alternative. I suspect you could use Groovy for this instead and run that from the command line.
Personally, I often write scripts in IntelliJ and then run them through QuPath - but not necessarily displaying any images. The two ways to do this are:
1 - Using Run -> Run for project in the script editor
The first method is useful if you want to batch-process one or more images within a project, effectively opening and processing them but without actually displaying this. If you need to query the current image, you can use commands such as
getProjectEntry()
getCurrentImageData()
getCurrentImageData().getServer()
to check which image is currently being processed, perhaps in order to figure out an appropriate json file to import. You would write your script for a single image, and apply it to as many as you want from within the project.
The second method gives a lot more flexibility, but also takes a bit more code. For example, you might loop through all the images/data files in a directory. You can read/write .qpdata files for an image with
PathIO.readImageData
PathIO.writeImageData
or even just read its object hierarchy if you do not need access to pixels with
PathIO.readHierarchy
But you should know that, with this approach, all I/O is internal to the script and so the 'currentImageData' isn't set automatically (as it is when you 'Run for project'); consequently, the methods in qupath.lib.scripting.QP/QPEx won't necessarily work because they don't know what image is intended. Depending upon what your script does, you might need to call
QP.setBatchImageData(imageData);
QPEx.setBatchImageData(imageData);
at some point (it's recommended to use both).
Hopefully one or more of these methods helps. If your interest is mostly on making the import straightforward, rather than necessarily running it from the command line, then there may be other options... such as adding an import option to the menus, or drag and drop support for the json files.