我经常在工作时流式传输新闻,并希望在广告期间静音,所以四处寻找并找到了这个
Stackoverflow 线程
这产生了一些好东西,并产生了以下脚本,它就像一个魅力:#!/bin/bash
#Mute, wait, unmute: attempt 1
for x in `amixer controls | grep layback` ; do
amixer cset "${x}" on ; done
echo Mute for how many seconds?
read v1
sleep $v1
for x in `amixer controls | grep layback` ; do
amixer cset "${x}" 700% ; done
这有效,但会导致终端屏幕上出现可怕的混乱:(只是一种味道(
<p>161 [~]$ MM<br>
numid=16,iface=MIXER,name='Master Playback Switch'<br>
; type=BOOLEAN,access=rw------,values=1<br>
: values=on<br>
Wrong control identifier: Playback<br>
Wrong control identifier: Switch'<br>
numid=15,iface=MIXER,name='Master Playback Volume'<br>
; type=INTEGER,access=rw---R--,values=1,min=0,max=127,step=0<br>
: values=0<br>
| dBscale-min=-95.25dB,step=0.75dB,mute=1<br>
Wrong control identifier: Playback<br>
Wrong control identifier: Volume'<br>...etc</p>
通过在 cset 后添加 -q 来清理一些
<p>166 [~]$ MM<br>
Wrong control identifier: Playback<br>
Wrong control identifier: Switch'<br>
Wrong control identifier: Playback<br>
Wrong control identifier: Volume'<br>
Wrong control identifier: Playback<br>
Wrong control identifier: Switch'<br>
Wrong control identifier: Playback<br>
Wrong control identifier: Volume'<br>
Wrong control identifier: Playback<br>
Wrong control identifier: Volume'<br>
Wrong control identifier: Playback<br>
Wrong control identifier: Switch'<br>
Wrong control identifier: Playback<br>
Wrong control identifier: Volume'<br>
amixer: Control default element write error: Operation not
permitted<br>...etc</p>
但是,为什么我会收到所有这些"错误的控件标识符"消息?
我试图man grep
但后来我的头掉了下来,我不得不把它重新贴上,现在我头痛了。我饿了。
干杯 欧姆内
试试这个:
read -p "Mute for how many seconds? " v1 ;
amixer controls | grep layback | grep -v ' Ma' |
xargs -I '{}' amixer -q cset '{}' on ;
sleep $v1 ;
amixer controls | grep layback | grep -v ' Ma' |
xargs -I '{}' amixer -q cset '{}' 700%
笔记:
- 主要问题似乎是像"播放掩码">这样的混音器,以及"播放通道图">与
amixer
选项不兼容。 使用grep -v
过滤掉这些混音器可以解决这个问题。 read
应该先走,否则静音持续输入 秒加上用户输入它们所需的时间。xargs
在这里并不是真的必要,但它似乎比使用 带有变量的循环。- 这些
;
可以更轻松地一次复制和粘贴到命令行。 在脚本中,不需要;
行结尾。