66

I have some long running scripts with breaks requiring input/interaction to continue but when I switch to another window I'd like to be notified (by sound) that a task is complete and now awaiting input.

I would prefer to be able to play an audio clip (*.mp3, *.ogg, etc.) but wouldn't care if the only solution is to make the PC Speaker beep noise.

Any ideas? I'm open to any CLI utilities I can install that play sounds that in turn I can execute when needed.

FYI: My System is running WinXP Pro.

UPDATE: Doh! My Windows > Control Panel > Sounds > Default Beep: was set to (none). Grrr...

Problem solved.

Community
  • 1
  • 1
scunliffe
  • 62,582
  • 25
  • 126
  • 161

9 Answers9

129

This will make a beep from within bash

echo -en "\007"
Greg Reynolds
  • 9,736
  • 13
  • 49
  • 60
43

Try this:

echo ^G

(^G is obtained by ctrl+G).

Note: you can't copy and paste this code in a batch file, it won't work. To obtain a ^G character in a file, type in a cmd window:

echo ^G > beep.txt

(again, ^G is obtained by ctrl+G).

Then you'll have a file named beep.txt, open it with notepad, there will be a square character. This is our ^G once it is saved in a file.

You can then copy and paste it in a batch file to make a sound (don't forget to put "echo" in front of it).

FWH
  • 3,205
  • 1
  • 22
  • 17
  • 1
    We're talking about a .bat or .cmd file, right ? You said you're running windows XP, but you're talking about a "bash" script, which is a linux command interpreter. – FWH Jul 17 '09 at 13:52
  • It could be anything I guess... a *.sh, an alias, *.bat or *.cmd. I should clarify that I'm currently running an alias... which echos a bunch of calls to run *.sh scripts. So I could put the "sound" bit anywhere in there. – scunliffe Jul 17 '09 at 13:56
  • 36
    In most shells (but not command/cmd), you need Ctrl-V Ctrl-G in order to type ^G. – ephemient Jul 17 '09 at 20:52
  • You can hold "Alt" key, then type "7" on the right side of your keyboard to generate "^G". This simplifies the process of this answer. – Brian Jun 05 '14 at 07:56
  • I had to type 07, just 7 makes "•". – srka Aug 12 '15 at 10:47
  • 1
    this worked for me, however, I have to put a pause otherwise is so fast that doesnt sound anything. How can I replace the pause? UPDATE: used TIMEOUT command for 2 seconds, and it worked :D – Kat Lim Ruiz Sep 08 '15 at 16:45
  • If your goal is to write a literal bell character in your text editor, you can save an intermediate step and echo ^G|clip to put the character straight into your clipboard. – durette Sep 29 '16 at 19:56
37

spd-say

sleep 2; spd-say 'get back to work'

Infinite loop with -w if you need extra motivation:

sleep 2; while true; do spd-say -w 'get back to work'; done

or if you prefer the carrot:

sleep 2; while true; do spd-say -t female1 -w "I'm done, come back to me, darling"; done

Pre-installed on Ubuntu 14.04 via the package speech-dispatcher: http://releases.ubuntu.com/trusty/ubuntu-14.04.4-desktop-amd64.manifest for blind people I suppose?

See also: https://askubuntu.com/questions/277215/how-to-make-a-sound-once-a-process-is-complete

Also add a popup

This combo is a life saver, b stands for beep:

b() ( spd-say 'done'; zenity --info --text "$(date);$(pwd)" & )

and then:

super-slow-command;b

If I'm somewhere in the room, I'll hear it and know that the long job is done.

Otherwise, I'll see the popup when I get back to my computer.

Related:

Listen to your cooler

I'm joking of course, but for compilation I noticed that I use often use this queue subconsciously. When the cooler stops humming for a while, it means that the compilation is over!

Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985
  • 1
    I guess you are referring to the Ubuntu platform here, which the links and the version number seems to corroborate. The OP didn't originally mention any specific platform, though now the question says Windows XP (sic). These things differ between systems; on macOS the command-line speech synthesizer `say` is installed by default; on many other systems, you will probably need to find a package with a different name. I hear `espeak` is pretty popular on Linux. – tripleee Apr 27 '17 at 06:37
  • This one spd-say is fun. But the voice quality is not good though. – CyberPlayerOne Jul 08 '22 at 10:54
11

I know your question was for Window but just putting this here for any Mac OSX users who come across this article. OSX 10+ comes with the say command:

say "I'm done"

For example:

sleep 5 && say "I'm done waiting 5 seconds"
Jay El-Kaake
  • 618
  • 6
  • 11
8

By setting this variable as follows

PROMPT_COMMAND="echo -en '\a'"

then bash will beep every time it shows the prompt. When you do not need it anymore,

unset PROMPT_COMMAND

am70
  • 591
  • 6
  • 8
7

To play the system sound from Windows command line you can run:

rundll32 user32.dll,MessageBeep

It should work on all version of Windows.

viktor-zin
  • 181
  • 1
  • 3
  • 1
    also this `rundll32.exe cmdext.dll,MessageBeepStub` – npocmaka Sep 16 '16 at 23:57
  • The commands for Linux did not work, even tho I'm using the bash setting in VSCode, but this one did (MessageBeep) gave me the default beep, after some attempts tho – 8koi Nov 29 '22 at 18:23
5

copy con beep.bat [Enter]

@echo off [Enter]

echo [Ctrl+G] [Enter]

[Ctrl+Z] [Enter]

beep.bat [Enter]

Community
  • 1
  • 1
  • FYI: Notepad.exe didn't like the ctrl-g, so when I edited this file with notepad and saved, it no longer beeped. Most likely an ASCII vs Unicode issue. I then used Notepad++ to edit the file created by typing the commands above, and that worked fine. – Brian B Mar 09 '12 at 16:35
2

Simple answer without ^G

echo -en "\007"
GlennG
  • 2,982
  • 2
  • 20
  • 25
0

In my bash profile I've added a BEEP to the script using @GregReynolds solution above then added this to PS1:

GREEN="\[\033[0;32m\]"
BEEP=$(echo -en "\007")
export PS1="$GREEN : ${BEEP}"

source ~/.bash_profile - you should hear the beep after the command prompt returns

I have git-autocomplete on usually so I've provided a much simplified version above

Rob Evans
  • 2,822
  • 1
  • 9
  • 15