bash 如何在 Mac OS X 10.6 中发出硬件提示音

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3127977/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 19:24:12  来源:igfitidea点击:

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

bashmacosapplescriptbeep

提问by elhombre

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

我只希望 Mac OS X 10.6 发出类似于 open suse 和其他发行版中的硬件蜂鸣声。我尝试了以下方法

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

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

applescript -> beep = Macintosh bell(我想要硬件蜂鸣声!)

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

有人知道如何在 bin/bash 或 applescript 中发出硬件蜂鸣声吗?

采纳答案by duskwuff -inactive-

There is no "hardware beep" in macOS.

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.

您想到的功能是非常古老(1990 年代之前)IBM PC 兼容硬件的产物。在大多数计算机配备声卡之前,大多数计算机都有一个连接到定时器芯片通道之一的小型扬声器或压电蜂鸣器。这可用于生成简单的音调或蜂鸣声。即使在许多计算机集成了声卡之后,在相当长的一段时间内,计算机仍然很普遍地将此输出路由到单独的内部扬声器。最近,许多计算机,尤其是膝上型计算机,已将此功能集成到板载声卡中。

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

(如果您对 PC 扬声器接口如何工作的技术细节感到好奇,这里有更多详细信息。)

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.

这种硬件从未出现在苹果电脑中。唯一可用的音频输出是通过声卡,而 macOS 中唯一的系统蜂鸣声是用户的警报声。

回答by broofa

tput belworks in most shells.

tput bel适用于大多数 shell。

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:

在 OS X 中,如果在终端不在前台时执行该命令,则此(以及任何其他使铃声响起的命令)也会为您提供徽章:

回答by Andrei

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

印刷\a并不总是对我有用(MBA,10.7.4)。我用这个代替:

say "beep"

回答by k00ka

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:

[更新] 不幸的是,最新的 OS X 中不再包含 Bells。尝试:

say -v Victoria Do your homework!

Use the following to explore voices:

使用以下方法探索声音:

say -v \?

回答by coffeejunk

write echo ^Gin the bash. to create the ^Gpress ctrl+vand then ctrl+g.

echo ^G在 bash 中。创建^G新闻ctrl+v然后ctrl+g

回答by Jason Ryan Taylor

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

这将遍历所有声音(适用于优胜美地):

say -v '?' | awk '{print }' | while read voice; do printf "using $voice...\n"; say -v $voice "hello, this is me using the $voice voice"; sleep 1; done

回答by Zaphod

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

-e 参数告诉 echo 处理转义字符。由于 \n 是换行符,\a 是铃音(与 Ctrl+G 相同)。

回答by fearless_fool

Play an arbitrary alert sound with afplay

播放任意提示音 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).

我很惊讶没有人提到afplay:这是播放任意声音文件的命令行程序。自 OS X 的原始版本(以及 NeXTSTEP,如果您的记忆力那么长)以来,它就已经存在了。

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 afplayis that you can choose your own sound file as an alert. For example, you could download one of these sound filesand pick your favorite.

您不仅限于系统声音;使用的一个好处afplay是您可以选择自己的声音文件作为警报。例如,您可以下载这些声音文件之一并选择您最喜欢的。

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

(如果您能找到电传打字机 Model 33 铃的录音,则加分!)

回答by Albert

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

在 OS X 终端下,执行命令: osascript -e 'beep'

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

使用 OSA(开放脚本架构)技术告诉 AppleScript 执行命令beep

回答by Alex Coplan

printf "\a"

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

如果您查看man printf,它会为您提供转义字符列表,包括\a

\a      Write a <bell> character.