In IntelliJ IDEA, how can I set an audio notification when a breakpoint is reached?
Asked Answered
F

3

8

With IntelliJ IDEA, when setting a breakpoint that isn't hit frequently (or not at all), I leave my computer. I'll return every 10 minutes or so to check if the breakpoint has been reached. It would be more efficient if I could hear when the breakpoint is reached. Is this possible?

  1. The following code works, but I need to execute an .mp4 file instead of .app. See the second block of code for that attempt, which doesn't work.

  2. Though the code works for .app, how would I set the breakpoint to execute that code when it is reached?

This works:

try {
   Runtime.getRuntime().exec("/usr/bin/open -a iTunes.app");
} catch (IOException e) {
   e.printStackTrace();
}

This doesn't:

try {
   Runtime.getRuntime().exec("MacintoshHD/Users/myusername/Music/iTunes/iTunes Media/Tones -a 01 Zelda Gets Item Alert Tone.m4a");
} catch (IOException e) {
   e.printStackTrace();
}

By the way, I did try putting quotes around the path items that had spaces. That didn't work either.

Freedman answered 31/8, 2016 at 14:29 Comment(0)
Y
3

Add this to Evaluate and log:

Clip clip = AudioSystem.getClip();
AudioInputStream inputStream = AudioSystem.getAudioInputStream(new File("some.wav"));
clip.open(inputStream);
clip.start();
Thread.sleep(10000);

or execute some application to do it:

try {
   Runtime.getRuntime().exec("\"C:\\Program Files (x86)\\Winamp\\winamp.exe\" \"C:\\some.mp4\"");
} catch (IOException e) {
   e.printStackTrace();
}
Yser answered 31/8, 2016 at 16:1 Comment(1)
Nice. I took this to the extreme and fixed the import bug with the newer Intellij. gist.github.com/philard/b92214e230e3c1de5f6d65b952b3de14Nerval
E
0

If you are on Windows, you can create a very simple script in PowerShell, which will make a beeping sound whenever it is ran. (This will run at frequency 500 for 3 seconds).

[console]::beep(500,3000)

Then in the evaluate section of the debugger, just add a watch variable that calls the script using PowerShell:

Runtime.getRuntime().exec("powershell.exe \"C:\\Users\\myusername\\test.ps1\"") 
Embay answered 22/5, 2021 at 17:49 Comment(0)
G
0

Since 2020.3, you can go to Settings | Appearance & Behavior | Notifications, choose the Breakpoint hit item and then check "Play sound".

enter image description here (image taken from the linked issue)

Unfortunately, it's not possible to configure which sound to play. A feature request is here.

Guillory answered 8/11, 2023 at 1:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.