开发者

How to make the hardware beep sound in Mac OS X 10.6

I开发者_StackOverflow社区 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?


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:

How to make the hardware beep sound in Mac OS X 10.6


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

say "beep"


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 \?


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


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


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


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.


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


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

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


printf "\a"

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

\a      Write a <bell> character.


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

:)


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


This works for me (mac os 10.14.6)

echo "\x07"  


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


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.


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


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜