215

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?

elhombre
  • 2,839
  • 7
  • 28
  • 28

17 Answers17

304

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:

Arjan
  • 22,808
  • 11
  • 61
  • 71
broofa
  • 37,461
  • 11
  • 73
  • 73
  • 40
    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 05 '12 at 18:37
  • 1
    Iterm users: this does beep, but doesn't create the alert badge :( – Eric Hu Aug 06 '13 at 22:45
  • 4
    @EricHu -iTerm2 now supports this - https://github.com/gnachman/iTerm2/commit/ef4589f02404075760e5bec44d0ffa8fb0639265 – broofa Dec 20 '13 at 18:59
  • 1
    `tput` is a great command with [lots of options](http://stackoverflow.com/a/20983251/24874). This command works on Linux as well. – Drew Noakes Jan 07 '14 at 22:26
  • 11
    `echo -e "\a"`also works on OS X and is probably more portable – wap26 Mar 13 '14 at 08:44
  • is tput bel only for Mac (although any shell in Mac)? – David Oct 28 '15 at 21:32
  • Using the above, I added it as an alias. So my scripts can alert me when they are done or have reached a particular milestone ... ```alias bell='tput bel'``` – nvanwyen Feb 04 '22 at 02:37
185

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

say "beep"
Andrei
  • 10,918
  • 12
  • 76
  • 110
  • the only way worked for me (OSX 10.8). Neither echo -e "\a" nor printf "\a" didn't work. – Valeriy Van Jul 30 '12 at 16:10
  • 20
    Wow - you can put anything in there, e.g.:say "build completed" – Pete Sep 27 '12 at 18:10
  • 1
    The best usage of it I see in [Little Snitch](http://www.obdev.at/products/littlesnitch/index.html) - when I run an fullscreen app and do not see regular LS popup warnings, it `say`s 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). – Andrei Feb 10 '13 at 12:29
  • @RandyHoward This is a really funny one, thanks! Here is a list of other options if anyone is interested: http://pastebin.com/raw.php?i=czJ8MVW3 – Andrei Mar 24 '13 at 14:28
  • 8
    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 03 '13 at 03:45
123

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 \?
pkamb
  • 33,281
  • 23
  • 160
  • 191
k00ka
  • 1,350
  • 2
  • 9
  • 10
61

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

coffeejunk
  • 744
  • 6
  • 11
  • 24
    `/usr/bin/printf "\a"` and `osascript -e "beep 1"` also work well enough – abe May 23 '11 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 '16 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](https://en.wikipedia.org/wiki/Control_character#In_ASCII) – coffeejunk Mar 27 '16 at 07:47
44

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!)

fearless_fool
  • 33,645
  • 23
  • 135
  • 217
  • [Typewriter bell](https://www.soundsnap.com/typewriter_bell_end_of_line_ding_office_blastwavefx_02384) might be close enough. – Andriy Makukha Jun 12 '20 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 '22 at 10:37
40

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
Gábor Bakos
  • 8,982
  • 52
  • 35
  • 52
30

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.

  • 5
    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 '17 at 07:25
  • That's an interesting bit of trivia, but it doesn't really answer the question... – Ian Dunn Oct 21 '17 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. –  Oct 21 '17 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 '17 at 22:03
  • There's some nice comments on the history of this in the documentation for the equivalent Windows function: https://msdn.microsoft.com/en-us/library/windows/desktop/ms679277(v=vs.85).aspx – c z Dec 20 '18 at 15:21
  • 3
    The terminal bell predates the PC of the 90's by nearly 100 years: https://en.wikipedia.org/wiki/Bell_character – kwerle Aug 28 '19 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).

Zaphod
  • 6,758
  • 3
  • 40
  • 60
16

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

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

Albert
  • 10,377
  • 4
  • 22
  • 27
10
printf "\a"

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

\a      Write a <bell> character.
Alex Coplan
  • 13,211
  • 19
  • 77
  • 138
9

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

:)

Nedudi
  • 5,639
  • 2
  • 42
  • 37
7

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

David Mulder
  • 26,123
  • 9
  • 51
  • 114
Oantby
  • 205
  • 2
  • 5
7

This works for me (mac os 10.14.6)

echo "\x07"  
morgancodes
  • 25,055
  • 38
  • 135
  • 187
  • 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! – Matt Sephton Oct 14 '20 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 '22 at 01:42
3

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

MaxF
  • 31
  • 1
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.

mschr
  • 8,531
  • 3
  • 21
  • 35
  • 1
    Xcode "behaviours" are only executed when the corresponding events occur in Xcode. They do not apply elsewhere in the system. –  May 18 '17 at 04:44
1

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

Sangram Shivankar
  • 3,535
  • 3
  • 26
  • 38
noah
  • 11
  • 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! – user3439894 Dec 31 '20 at 16:04
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
Sankarganesh Eswaran
  • 10,076
  • 3
  • 23
  • 24
  • 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 – justFatLard Feb 03 '23 at 06:31