如何在 Mac OS X 10.6 中发出硬件蜂鸣声
我只是希望 Mac OS X 10.6 能像 open suse 和其他发行版中那样发出硬件蜂鸣声。我尝试了以下方法
终端 ->蜂鸣= -bash:蜂鸣:找不到命令
终端->说 beep = 语音发出蜂鸣声(不是硬件蜂鸣声,但很棒;))
applescript -> beep = Macintosh 铃声(我想要硬件蜂鸣声!)
有人知道如何在 bin/bash 或 applescript 中发出硬件蜂鸣声吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(17)
打印
\a
对我来说并不总是有效(MBA,10.7.4)。我用这个代替:Printing
\a
did not always work for me (MBA, 10.7.4). I use this instead:事实上,以下内容是有效且有些旋律的:[更新] 不幸的是,Bells 不再包含在最新的 OS X 中。尝试:
使用以下内容来探索声音:
Indeed, the following is effective and somewhat melodic:[Update] Unfortunately Bells is no longer included in latest OS X. Try:
Use the following to explore voices:
在 bash 中写入
echo ^G
。要创建^G
,请按ctrl+v
,然后按ctrl+g
。write
echo ^G
in the bash. to create the^G
pressctrl+v
and thenctrl+g
.使用
afplay
播放任意警报声音我很惊讶没有人提到
afplay
:这是播放任意声音文件的命令行程序。它自从 OS X 最初发布以来就已经存在了(如果你还记得的话,还有 NeXTSTEP)。例如,您可以从命令行运行它或将其放入脚本中:
您不仅限于系统声音;使用
afplay
的优点之一是您可以选择自己的声音文件作为警报。例如,您可以下载 这些声音文件之一并选择您最喜欢的。(如果您能找到 Teletype 33 型电铃的录音,可加分!)
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:
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):
macOS 中没有“硬件蜂鸣声”。
您正在考虑的功能是非常古老的(20 世纪 90 年代之前)IBM PC 兼容硬件的产物。在大多数计算机配备声卡之前,大多数机器都有一个小型扬声器或压电蜂鸣器连接到定时器芯片的通道之一。这可用于生成简单的音调或蜂鸣声。即使在许多计算机集成了声卡之后,在相当长的一段时间内,计算机将此输出路由到单独的内部扬声器仍然很常见。最近,许多计算机,尤其是笔记本电脑,已将此功能集成到板载声卡中。
(如果您对 PC 扬声器界面如何工作的技术细节感到好奇,这里有更多详细信息。)
这种硬件在苹果电脑中从未存在过。唯一可用的音频输出是通过声卡,macOS 中唯一的系统蜂鸣声是用户的警报声。
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.
在终端中输入:
-e 参数告诉 echo 处理转义字符。由于 \n 是换行符,\a 是铃声字符(与 Ctrl+G 相同)。
In the terminal type :
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).
在 OS X 终端下,执行命令:
osascript -e 'beep'
使用 OSA(开放脚本架构)技术告诉 AppleScript 执行命令
beep
。Under OS X terminals, execute command:
osascript -e 'beep'
Using OSA (Open Script Architecture) technology to tell AppleScript to execute command
beep
.如果您查看
man printf
,它会为您提供转义字符列表,包括\a
:If you look at
man printf
, it gives you a list of escaped characters, including\a
:如果您需要某些东西,听起来像“重要”,
您可以使用
或
If you need something, that sounds like "important"
you can use
or
????
printf "\a"
也可以在终端中工作并播放设置的警报声音。printf "\a"
also works in a terminal and will play the set alert sound.这对我有用(mac os 10.14.6)
This works for me (mac os 10.14.6)
在 MacOS X 上,必须激活“声音警告”选项(终端/首选项)才能发出声音。
on MacOS X, the "sound warning" option (Terminal/Preferences) has to be activated to get a sound.
osascript -e '告诉应用程序“系统事件”
发出蜂鸣声'osascript -e 'tell application "System Events"
to beep'如果您安装了 Xcode,您可以发出蜂鸣声/响铃。我还没有想到我可以让
printf "\a"
字符在 C 中工作。有一种方法可以让声音在程序运行时工作,启动 Xcode,在 Xcode 下的下拉菜单,首选项,行为,选中第一个框“播放声音”,从列表中选择或添加声音。
我相信,这是一种方法,但仅限于程序运行时。
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.
如需更多选择,请聆听并选择
For more options, hear and pick
tput bel
适用于大多数 shell。在 OS X 中,如果在终端不在前台时执行该命令(以及任何其他使铃声响起的命令),也会为您带来徽章:
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: