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()
Thread.sleep(1000)
"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())

if(name.contains("hematoxylin")){
    "rundll32 user32.dll,MessageBeep".execute()
    Thread.sleep(1000)
    "rundll32 cmdext.dll,MessageBeepStub".execute()
}
print "Done!"

Cheers all, and happy holidays!

6 Likes

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

 java.awt.Toolkit.defaultToolkit.beep()

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

2 Likes

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