65

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.

3
  • 2
    on Windows 10 this works for me: start wmplayer "C:\Windows\Media\Alarm10.wav" && timeout 5 && taskkill /im wmplayer.exe
    – JinSnow
    Jun 19, 2020 at 9:49
  • Is this Windows or Linux? You specify Windows, but also bash? Dec 5, 2021 at 23:14
  • @Lazerbeak12345 this was cygwin bash running on Windows (XP at the time, now Win10/Win11)
    – scunliffe
    Dec 8, 2021 at 5:11

9 Answers 9

125

This will make a beep from within bash

echo -en "\007"
7
  • 18
    Slightly simpler alternatives: echo -ne '\a' and printf '\a'. Also note that in some Linux distros (e.g., Ubuntu), the bell sound may be suppressed - see askubuntu.com/questions/19906/beep-in-shell-script-not-working
    – mklement0
    Jan 22, 2014 at 20:22
  • 2
    In Cygwin you have to enable beep sound in terminal oprtions.
    – pbies
    May 1, 2015 at 18:07
  • In my clearOS server I am using echo -en "\a" > /dev/console in a bash script
    – Arun
    Aug 18, 2016 at 10:38
  • 1
    If the question specifies Windows XP, why would you give this answer that only works in Linux?
    – Jolta
    Nov 11, 2016 at 16:28
  • 3
    shorter printf \\a Dec 13, 2019 at 1:36
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).

7
  • 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, 2009 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, 2009 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, 2009 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 5, 2014 at 7:56
  • 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 Sep 8, 2015 at 16:45
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!

2
  • 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, 2017 at 6:37
  • This one spd-say is fun. But the voice quality is not good though. Jul 8, 2022 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"
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

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.

2
  • 1
    also this rundll32.exe cmdext.dll,MessageBeepStub
    – npocmaka
    Sep 16, 2016 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, 2022 at 18:23
5

copy con beep.bat [Enter]

@echo off [Enter]

echo [Ctrl+G] [Enter]

[Ctrl+Z] [Enter]

beep.bat [Enter]

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 9, 2012 at 16:35
2

Simple answer without ^G

echo -en "\007"
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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.