Play sound on mac terminal

Posted on

QUESTION :

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?

ANSWER :

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/.

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

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.

tput bel works in most shells.

From this answer on a related Stack Overflow question:

Leave a Reply

Your email address will not be published. Required fields are marked *