20

Is there a way to play OSX alert sounds from terminal? The alert sounds that are listed in System Preferences > Sound > Sound Effect Tab

5 Answers 5

27

If you have "audible bell" enabled in your Terminal Settings under Advanced, BEL control characters will sound the default alert sound.

To try this, issue the echo command followed by control+v control+g. If you type it right, it will look like this:

$ echo ^G

and when you press return, the alert will sound.

(control+v is a shell escape for the immediately-following control character.)

The afplay command can also be used to play a specific sound file:

$ afplay /System/Library/Sounds/Funk.aiff 
1
  • I use this for playing sounds in MAMP PRO: <? passthru('/usr/bin/afplay /System/Library/Sounds/Sosumi.aiff'); ?>
    – EDP
    Dec 17, 2017 at 13:42
9

Another option, with less modifier keys, is to use the command tput bel.

2
  • 2
    I liked this answer because I disabled the "audible bell" in my terminal settings, but tput bel calls the "visual bell" so I still get the alert that I want without the noisy one
    – Purefan
    Jan 26, 2016 at 9:22
  • Today, the accepted answer (echo ctrl+v ctrl+g) also shows the visible bell when my Mac is muted. Glad they fixed this since 2016
    – Ky -
    Jul 8, 2020 at 15:15
9

I like zigg's solution. In order to keep it short I did this:

In /Users/{username}/.bash_profile add a line

alias taskready='afplay /System/Library/Sounds/Hero.aiff'

Quit the terminal and open the terminal. Now you can use the shorthand command taskready.

You can choose from:

Basso.aiff  Frog.aiff   Hero.aiff   Pop.aiff    Submarine.aiff
Blow.aiff   Funk.aiff   Morse.aiff  Purr.aiff   Tink.aiff
Bottle.aiff Glass.aiff  Ping.aiff   Sosumi.aiff
3
  • 2
    done is used in bash to close for/while loops, maybe a different name might be better
    – nohillside
    Aug 29, 2019 at 7:24
  • @nohillside it luckily didn't cause any problems so far... thanks! Do you have a short keyword suggestion?
    – Matt
    Aug 30, 2019 at 16:35
  • 1
    See man bash for all keywords to avoid :-)
    – nohillside
    Aug 30, 2019 at 16:49
7

Not exactly what OP wants but may still prove useful to people.

say beep

2

Another way to beep is echo -e '\a'

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .