116

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?

6 Answers 6

194

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

3
  • I was using say till now, afplay did the trick. Thanks!
    – rk.
    Commented May 22, 2013 at 22:19
  • 4
    Sweet! 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 Commented Jan 27, 2015 at 17:25
  • 2
    In macOS Catalina, I had to use say -v '?' with single quotes because of zsh.
    – Funktional
    Commented Nov 12, 2020 at 1:51
26

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

13
  • 2
    Didn't work for me. Do I need a package?
    – rk.
    Commented May 22, 2013 at 21:37
  • 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
    Commented May 22, 2013 at 21:38
  • Ah! Terminal sounds were not enabled. Also, is there a decent bell/alert compared to the dull thud sound this command makes?
    – rk.
    Commented May 22, 2013 at 21:41
  • 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
    Commented May 22, 2013 at 21:45
  • Ohk, I will use that setup as a last resort ;)
    – rk.
    Commented May 22, 2013 at 21:50
9

Hear and pick

ls /System/Library/Sounds/ | awk '{print $1}' | while read sound; do printf "using $sound...\n"; afplay /System/Library/Sounds/$sound; sleep 0.5; done

ls /System/Library/PrivateFrameworks/ScreenReader.framework/Versions/A/Resources/Sounds/ | awk '{print $1}' | while read sound; do printf "using $sound...\n"; afplay /System/Library/PrivateFrameworks/ScreenReader.framework/Versions/A/Resources/Sounds/$sound; sleep 0.5; done
1
  • 1
    Thank you! Very helpful to try out the different sounds
    – nickel715
    Commented Feb 9 at 9:49
7

tput bel works in most shells.

From this answer on a related Stack Overflow question:

6

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.

3
  • @tmanok On a mac? ctrl+G by itself does not do anything for me on a mac.
    – wisbucky
    Commented Feb 20, 2018 at 19:52
  • Oh? It does on Sierra and Yosemite for me.... Odd
    – Tmanok
    Commented Feb 21, 2018 at 6:33
  • 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
    Commented Feb 21, 2018 at 6:34
0

There's one more way that can be useful in cases like, let's say you forgot to set the alert and in the middle of the process, and on Iterm. Simply Cmd + Option + A while in terminal screen lets you have a notification in the end of the process.

2
  • 1
    This doesn't answer the question.
    – Toto
    Commented Feb 3, 2022 at 9:56
  • I found this useful, why the downvotes? It really does add to the other answers. Commented Oct 30, 2022 at 23:19

You must log in to answer this question.

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