218

I just want that Mac OS X 10.6 does a hardware beep sound like in open suse and other distributions. I tried following approaches

Terminal -> beep = -bash: beep: command not found

Terminal -> say beep = voice speaks out beep (Not a Hardware beep but awesome ;) )

applescript -> beep = Macintosh bell (I want a Hardware beep!)

Does anybody know how to make the Hardware beep in bin/bash or applescript?

12
  • 3
    @elhombre, what makes you think Mac OS X can even do such a thing?
    – Carl Norum
    Jun 27, 2010 at 16:38
  • 24
    Try: say "beep" if you don't find anything, closest I can think of. Jun 27, 2010 at 16:42
  • 37
    @Patrik - +1, nice. printf "\a" gives the OS beep, if that helps.
    – Carl Norum
    Jun 27, 2010 at 16:44
  • 13
    @Carsten: a Mac is a PC. PC = Personal Computer. It's just not an IBM(-compatible) PC.
    – Paul R
    Jun 27, 2010 at 21:09
  • 4
    An Intel-based MAC is an IBM-compatible PC Nov 2, 2012 at 4:11

17 Answers 17

305

tput bel works in most shells.

In OS X, this (and any other command that makes the bell go off) also gets you a badge if the command is executed when Terminal was not in the foreground:

7
  • 41
    Awesome side effect (at least in Lion terminal) of having a bell go off in your terminal when it is in the background is that the icon on the doc jumps, and you get a red indicator saying there has been something completed. Try this: "sleep 5; tput bel" run that command and then tab out of the terminal, when the bell goes off you get an alert. Just what I was looking for!
    – BadPirate
    Jan 5, 2012 at 18:37
  • 1
    Iterm users: this does beep, but doesn't create the alert badge :(
    – Eric Hu
    Aug 6, 2013 at 22:45
  • 4
    @EricHu -iTerm2 now supports this - github.com/gnachman/iTerm2/commit/…
    – broofa
    Dec 20, 2013 at 18:59
  • 1
    tput is a great command with lots of options. This command works on Linux as well. Jan 7, 2014 at 22:26
  • 11
    echo -e "\a"also works on OS X and is probably more portable
    – wap26
    Mar 13, 2014 at 8:44
193

Printing \a did not always work for me (MBA, 10.7.4). I use this instead:

say "beep"
5
  • the only way worked for me (OSX 10.8). Neither echo -e "\a" nor printf "\a" didn't work. Jul 30, 2012 at 16:10
  • 24
    Wow - you can put anything in there, e.g.:say "build completed"
    – Pete
    Sep 27, 2012 at 18:10
  • 1
    The best usage of it I see in Little Snitch - when I run an fullscreen app and do not see regular LS popup warnings, it says me them (only when in fullscreen), i.e. what app has been blocked trying to connect to some host. Really nice. Some time ago I needed to track changes on a website during a day, so instead of sitting in front of my screen, I used say to let me know what is going on (obviously meaningful text only - those were sale ads).
    – Andy
    Feb 10, 2013 at 12:29
  • @RandyHoward This is a really funny one, thanks! Here is a list of other options if anyone is interested: pastebin.com/raw.php?i=czJ8MVW3
    – Andy
    Mar 24, 2013 at 14:28
  • 9
    Haha. You can make people wonder if they're hearing things by putting two voices on top of each other: Run say "Pay attention to me" & and say -v Whisper "I own you" & consecutively.
    – Matt
    Aug 3, 2013 at 3:45
126

Indeed, the following is effective and somewhat melodic:

say -v Bells "dong dong dong"

[Update] Unfortunately Bells is no longer included in latest OS X. Try:

say -v Victoria Do your homework!

Use the following to explore voices:

say -v \?
6
  • 10
    say -v Daniel harry potter harry potter Jul 30, 2015 at 21:29
  • 1
    Or just: say -v Bells "beep".
    – kenorb
    Jan 30, 2016 at 23:02
  • 1
    The is no Beels voice on my up-to-date macos.
    – Martin
    Jul 14, 2017 at 13:24
  • 1
    Yes, Bells seems to have been removed. Use say -v '?' to list all voices. Use say -v '?' | egrep `echo $LANG | sed "s/\..*//"` to list voices for your current language.
    – k00ka
    Sep 20, 2017 at 18:09
  • 5
    Bells can be re-added through System Preferences all the way up to Big Sur! System Preferences > Accessibility > Spoken Content > System Voice > Customize
    – Jase
    Jan 28, 2021 at 15:07
61

write echo ^G in the bash. to create the ^G press ctrl+v and then ctrl+g.

3
  • 24
    /usr/bin/printf "\a" and osascript -e "beep 1" also work well enough
    – abe
    May 23, 2011 at 11:31
  • 2
    can anyone explain what echo ^G is doing (i.e. what does this command say in layman's terms) ? Is this a special character that meens beep to OSX? Are there any other related special characters? @mxhaack @wongo888
    – Eric Jones
    Mar 25, 2016 at 18:04
  • 3
    @EricJones ^G is a "control character" i.e. a non-printable character that is/was used to cause a certain effect like for example triggering the bell/beep. Have look at this wikipedia article
    – coffeejunk
    Mar 27, 2016 at 7:47
47

Play an arbitrary alert sound with afplay

I'm surprised nobody has mentioned afplay: that's the command line program that plays arbitrary sound files. It's been around since the original releases of OS X (and NeXTSTEP, if your memory is that long).

For example, you can run this from the command line or put it in a script:

$ afplay /System/Library/Sounds/Ping.aiff

You're not limited to system sounds; one advantage of using afplay is that you can choose your own sound file as an alert. For example, you could download one of these sound files and pick your favorite.

(Extra points if you can find a recording of an Teletype Model 33 bell!)

2
  • Typewriter bell might be close enough. Jun 12, 2020 at 12:04
  • 2
    afplay /System/Library/PrivateFrameworks/ScreenReader.framework/Versions/A/Resources/Sounds/AnimationFlyToDownloads.aiff is a typewriter bell that may be installed by default on macOS 12.3 (or it came with Xcode).
    – Blaise
    May 21, 2022 at 10:37
44

This will loop through all the voices (works on Yosemite):

say -v '?' | awk '{print $1}' | while read voice; do printf "using $voice...\n"; say -v $voice "hello, this is me using the $voice voice"; sleep 1; done
2
  • 3
    Hilarious, such a treasure! :D
    – idleherb
    Jan 20, 2019 at 14:32
  • Gold: works in Big Sur too.
    – Aaron A.
    Jun 26, 2022 at 3:27
33

There is no "hardware beep" in macOS.

The functionality you're thinking of is an artifact of very old (pre-1990s) IBM PC-compatible hardware. Before most computers had sound cards, most machines had a small speaker or piezo buzzer connected to one of the channels of a timer chip. This could be used to generate simple tones or beeps. Even after many computers integrated sound cards, it remained common for quite some time for computers to route this output to a separate internal speaker. More recently, many computers, especially laptops, have integrated this functionality into the onboard sound card.

(If you're curious about the technical details of how the PC speaker interface worked, there are more details here.)

This hardware has never existed in Apple computers. The only audio output available is through the sound card, and the only system beep in macOS is the user's alert sound.

6
  • 6
    After 7 years, the search came to it's end^^ Thank you Dog on the Internet. But I still enjoy all the creative ways people answer the question, so keep em coming!
    – elhombre
    May 19, 2017 at 7:25
  • That's an interesting bit of trivia, but it doesn't really answer the question...
    – Ian Dunn
    Oct 21, 2017 at 20:14
  • 3
    @IanDunn Sure it does -- read the first and last paragraphs carefully. The question is asking for something that doesn't exist.
    – user149341
    Oct 21, 2017 at 20:31
  • 1
    Ah, you're right, I didn't read the OP's question and comments closely enough, and thought that they just wanted the sound itself, regardless of whether it came via software or hardware. My bad.
    – Ian Dunn
    Oct 22, 2017 at 22:03
  • 3
    The terminal bell predates the PC of the 90's by nearly 100 years: en.wikipedia.org/wiki/Bell_character
    – kwerle
    Aug 28, 2019 at 21:28
30

In the terminal type :

echo -e "\a"

The -e parameter tells echo to process escaped characters. As the \n is the new line character, the \a is the bell one (the same as Ctrl+G).

2
  • One benefit of this approach is that it works in Linux (and others?) as well. As mentioned elsewhere, you might also try printf "\a"
    – rinogo
    Jul 9, 2015 at 17:23
  • 2
    For those who love the bell but are lazy about quotes, echo -e \\a works also. Feb 19, 2016 at 8:07
16

Under OS X terminals, execute command: osascript -e 'beep'

Using OSA (Open Script Architecture) technology to tell AppleScript to execute command beep.

10
printf "\a"

If you look at man printf, it gives you a list of escaped characters, including \a:

\a      Write a <bell> character.
10

If you need something, that sounds like "important"

you can use

tput bel && sleep 0.33s && tput bel && sleep 0.33s && tput bel && sleep 0.33s && tput bel && sleep 0.33s && tput bel && sleep 0.33s && tput bel && sleep 0.33s && tput bel && sleep 0.33s && tput bel && sleep 0.33s && tput bel && sleep 0.33s && tput bel && sleep 0.33s

:)

8

This works for me (mac os 10.14.6)

echo "\x07"  
2
  • This works well as both audio and visual alert, as it also flashes the screen so you don't miss the notification if you have the sound turned down. It also adds a badge to Terminal app, and shows a bell icon in the tab that issued it. I think that's all - more than enough! Oct 14, 2020 at 22:40
  • I needed to add an -e for it to work: echo -e "\x07". Also as an FYI, x07 is the hex ascii code for BEL.
    – wisbucky
    Apr 23, 2022 at 1:42
7

printf "\a" also works in a terminal and will play the set alert sound.

3

on MacOS X, the "sound warning" option (Terminal/Preferences) has to be activated to get a sound.

1
  • 2
    Actually it's called "Audible bell". It's in Settings/Advanced. Aug 10, 2013 at 3:31
1

osascript -e 'tell application "System Events" to beep'

1
  • 1
    beep is a part of Standard Additions in AppleScript and therefore you do not need to use, nor should you use, System Events, simply osascript -e 'beep' is all that is necessary. However, the OP already stated they tried beep and it does not produce what's wanted! Dec 31, 2020 at 16:04
1

If you've got Xcode installed you can make a beep/bell. I haven't figured that I can make the printf "\a" character work in C.

There's one way to make the tone work as the program runs, start Xcode, drop down menu under Xcode, Preferences, Behaviours, check the first box "Play sound", choose from the list or add a sound.

That's one way to do it, but only as the program runs, I believe.

1
  • 2
    Xcode "behaviours" are only executed when the corresponding events occur in Xcode. They do not apply elsewhere in the system.
    – user149341
    May 18, 2017 at 4:44
0

For more options, hear and pick

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

ls /System/Library/PrivateFrameworks/ScreenReader.framework/Versions/A/Resources/Sounds/ | awk '{print $1}' | while read sound; do printf "using $voice...\n"; afplay /System/Library/PrivateFrameworks/ScreenReader.framework/Versions/A/Resources/Sounds/$sound; sleep 0.5; done
1
  • While some of the other answers worked and invoked the configured bell sound. I found myself wanting something specifically less obtrusive. I ended up going with afplay /System/Library/PrivateFrameworks/ScreenReader.framework/Versions/A/Resources/Sounds/RotorLeft.aiff thanks to your suggestion here. I didn't want to listen to all of the sounds, but I used ls on the aforementioned folders and played a select few Feb 3, 2023 at 6:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.