QuPath audible alert (Windows) when script is complete

Hi all,

Some scripts really take a long time to finish, and I cannot always be at my computer.

This is just a quick note for anyone into scripting, but not so into scripting that command line work is second nature. I have wanted to be able to create an audible alert once a script is done for a while now, as I am often up and about the core facility on various microscopes yet still want to know when a script is finished so that I could start another, or adjust a parameter and run another test.

It turns out it is as simple as adding a line or few of code at the end of the script.

"rundll32 user32.dll,MessageBeep".execute()
"rundll32 cmdext.dll,MessageBeepStub".execute()
print "Done!"

The two different execute lines are just two ways of doing the same thing. The script will cause a double beep. If you omit the sleep line (1000 milliseconds), the two beeps happen right on top of each other and you only hear one beep.
Courtesy of this post.

This will play the audible alert every time a script is finished, so once per entry in a project. If you want something that only plays after the final image, you could add an “if” statement checking for the image name (simpler) or adjust the entire script to progress through project entries using a structure similar to a recent post.

Check each image name in the “Run for Project” list for a particular text string. If that string is only in the final image in the list, the sounds will only play once, at the end.

def name = GeneralTools.getNameWithoutExtension(getCurrentImageData().getServer().getMetadata().getName())

    "rundll32 user32.dll,MessageBeep".execute()
    "rundll32 cmdext.dll,MessageBeepStub".execute()
print "Done!"

Cheers all, and happy holidays!


If you want something cross-platform, this might work:


At least it makes a sound on a Mac (haven’t tried it on Windows or Linux).


Confirm that it works on Windows10. Though depends on your default Windows audio settings.