QuPath run scripts in existing instance

I’m currently working on some QuPath scripts, using a Java IDE. I’m hoping to be able to make changes to the script and run it from my IDE, while seeing the changes applied in the running instance of QuPath.

Is there a way to run a script inside an existing QuPath instance, from an external application? I see that the QuPath binary has a script command, however that is for running scripts headlessly, correct?

I may try to write a TCP server groovy script which accepts scripts and runs them through the Java scripting engine (groovyception!), but I wanted to make sure that there was no better way to do this already built into QuPath.

Yes.

Not exactly… but if you open the same file in both QuPath and the IDE, and save any changes you make in the IDE, then the script will automatically refresh when activated again in the QuPath script editor.

This is the way I use an IDE to develop scripts, while still running the latest version in QuPath. I toggle between applications and use Ctrl + R to run the script in QuPath (ensuring the script editor is in focus).

The option is controlled with File → Auto refresh files.

@petebankhead I went ahead and wrote a little script that exposes a local TCP server which accepts Groovy code and runs it. The code it runs has all the capabilities of a regular QuPath script. I also redirected all output from the script back to the TCP client. From my initial testing, it works very well!

The terminal in the bottom right corner has opened a TCP session to script’s server. I ran a short snippet that added the red circle which can be seen in the top left corner of the QuPath image.

This also allows for the code to be developed on a remote system with SSH port forwarding connecting to the machine where QuPath is running.

I am in the process of cleaning up the code, and I will try to post it here (along with some client scripts for the IDE) when I am finished.

2 Likes

I finished writing the client script for Eclipse and connected it as an external tool! Everything is working amazingly!

Here is a demo GIF:

3 Likes

This looks great! Would you be willing to create a new topic in here posting the script with a brief explanation how to use it…? No worries if not :slight_smile:

(We don’t yet have a good way of managing scripts and extra contributions; I’m just using gists for now for some minimal version control. But need to figure out a better strategy soon!)

Sure, I’ll try to do that within the next few days.

Hopefully this script proves to be as useful for others as it is to me!

5 Likes

To the four people who liked that messasge:
Haven’t forgotten, I’m actually writing instructions right now! Will try to get it finished and posted by Monday.

4 Likes