Play sound on mac terminal

57

27

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?

rk.

Posted 2013-05-22T21:23:41.113

Reputation: 685

Answers

97

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

Lri

Posted 2013-05-22T21:23:41.113

Reputation: 34 501

1Sweet! You can use say -v ? (in Yosemite, at least) to get a list of voices installed -- I had several! Here's a little script to say what you want in every available voice: for i in $(say -v \? | awk '{print $1;}'); do echo $i; say -v $i "Build terminated\!"; done – scorpiodawg – 2015-01-27T17:25:59.120

I was using say till now, afplay did the trick. Thanks! – rk. – 2013-05-22T22:19:06.187

14

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

demure

Posted 2013-05-22T21:23:41.113

Reputation: 4 605

What does the -e option do? It is not listed in the man pages – Startec – 2015-05-27T20:48:53.187

A way to make a command-line alias for one (without escape sequences) is: alias beep='tput bel' – Jeff Clayton – 2015-11-21T14:31:27.530

1Didn't work for me. Do I need a package? – rk. – 2013-05-22T21:37:11.557

What version of OS X are you on? Also, check your terminal emulator's settings, and make sure you don't have bell disabled. – demure – 2013-05-22T21:38:30.813

Ah! Terminal sounds were not enabled. Also, is there a decent bell/alert compared to the dull thud sound this command makes? – rk. – 2013-05-22T21:41:45.777

I use iTerm2 myself, which uses growl (so bells go to growl), via growl I add another sound to iTerm2 alerts. Yeah, kind of round-about. – demure – 2013-05-22T21:45:31.150

Ohk, I will use that setup as a last resort ;) – rk. – 2013-05-22T21:50:17.293

You can change the sound played in System Preferences. The sound used by terminal is just the system wide alert sound which you can find in the Sound prefs. – Tonny – 2013-05-22T21:52:19.700

@Tonny quite valid, and I should have recalled to mention that. I don't use that method as I wish to tell the difference between the command line and the rest of the system beeping at me. – demure – 2013-05-22T21:57:52.497

@demure Ideally me too, but I run so few scripts (on OSX) that I never bothered to setup something up like that. I just enable "Visible bell" to get that little extra feedback. – Tonny – 2013-05-22T22:02:32.207

discovered that echo ^G and tput bel have the same effect. – rk. – 2013-05-22T22:02:54.717

Not sure why this warranted a down vote :/ – demure – 2013-09-19T20:11:24.490

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.

wisbucky

Posted 2013-05-22T21:23:41.113

Reputation: 1 522

@tmanok On a mac? ctrl+G by itself does not do anything for me on a mac. – wisbucky – 2018-02-20T19:52:08.263

Oh? It does on Sierra and Yosemite for me.... Odd – Tmanok – 2018-02-21T06:33:24.180

But it isn't working on my 10.6 machine- maybe some of my CLI Tools or Homebrew is screwing with it. I'll retract my comment, apologies. – Tmanok – 2018-02-21T06:34:50.213