问题
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?
回答1:
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.
回答2:
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:
回答3:
Printing \a
did not always work for me (MBA, 10.7.4). I use this instead:
say "beep"
回答4:
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 \?
回答5:
write echo ^G
in the bash. to create the ^G
press ctrl+v
and then ctrl+g
.
回答6:
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
回答7:
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).
回答8:
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!)
回答9:
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.
回答11:
printf "\a"
also works in a terminal and will play the set alert sound.
回答12:
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
:)
回答13:
on MacOS X, the "sound warning" option (Terminal/Preferences) has to be activated to get a sound.
回答14:
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.
回答15:
osascript -e 'tell application "System Events" to beep'
来源:https://stackoverflow.com/questions/3127977/how-to-make-the-hardware-beep-sound-in-mac-os-x-10-6