Play sound on mac terminal

I have a script running in the background and sends me an alert every few minutes. I want the alert to be in the form of a beep.

Question: How can I play a beep in mac terminal?


Solution 1:

printf \\a and osascript -e beep play the default alert sound, but they are silent if the alert volume is set to zero. printf \\a is also silent if an audible bell is disabled.

You could also use afplay or say:

afplay /System/Library/Sounds/Funk.aiff
say done

There are more sound effect files in /System/Library/PrivateFrameworks/ScreenReader.framework/Versions/A/Resources/Sounds/.

Solution 2:

The simplest way is the use a bell echo -e "\a"

Solution 3:

Another way is to echo ^G. But you don't literally type the ^G. Instead, type ctrl+v, ctrl+g, which will appear as echo ^G.

Solution 4:

tput bel works in most shells.

From this answer on a related Stack Overflow question:

  • bash - How to make the hardware beep sound in Mac OS X 10.6 - Stack Overflow