I'm running a long running custom nodejs script and would like to be notified when the script is completed.
How do I make nodejs trigger the "System Bell"?
Output the BELL character (Unicode 0007) to the standard output.
console.log('\u0007');
Update 2023
Solution above doesn't work anymore, but writing directly to stdout still works (tested on Node.js v14.20):
process.stdout.write('\u0007');
References
The console.log('\u0007') didn't work for me running VSCode on windows 10. The following code did work:
import { exec } from 'child_process'
exec(`rundll32 user32.dll,MessageBeep`)
console.log
version worked for me, it did not work after building an electron app with the code. Your solution also works for electron apps on windows 10.
Commented
Dec 7, 2020 at 20:13
I know this question is tagged unix, but I found it from Google so here is a Windows PowerShell solution.
The current answer works fine in Windows, but I wanted something a bit more unique than the standard Windows tone so this worked better for my needs:
const { exec } = require('child_process');
// Single beep
exec("[console]::beep(1000, 500)", {'shell':'powershell.exe'});
// Multiple beeps
exec("1..3 | %{ [console]::beep(1000, 500) }", {'shell':'powershell.exe'});
console.log('\u0007');