我是新来的我和我年纪大了一点。我决定开始学习shell脚本,因为我喜欢Linux和它给我一个理由在家中自动完成很多任务。而且我想学习编程,也许有一天可以换工作。
无论如何,我做了一个脚本来提高,降低和静音我的体积和发送通知。但是,当我静音,它显示音量,并在它的静音(播放声音时),它显示的通知“静音”。它正在做相反的事情。
以下是代码:link
#!/bin/bash
# Manage volume and send notify with dunst
msgId="777" # unique ID for dunstify to replace the notification
getvol=$(amixer get Master | grep % | cut -d '[' -f 2 | cut -d ']' -f 1) # get vol %
muted=$(amixer get Master | grep % | cut -d '[' -f 4 | cut -d ']' -f 1 ) # check if on/off
function notification {
dunstify -u low -r $msgId "$getvol"
}
case $1 in
up)
amixer sset Master 3%+ > /dev/null
notification
;;
down)
amixer sset Master 3%- > /dev/null
notification
;;
mute)
amixer sset Master toggle > /dev/null
if [ $muted == "off" ]; then
dunstify -u low -r $msgId "Mute"
else
notification
fi
;;
esac
它是这样的:
./ vol.sh向上
./ vol.sh向下
./ vol.sh静音(这是问题所在)
我可以将if [$ muted ==“ off”]更改为if [$ muted ==“ on”],但这对我来说没有意义。
PS:请注意,当它在 axer get Master 中显示时,表示声音已关闭,而不是静音状态已关闭。
谢谢!随时给我其他的提示了。
答案 0 :(得分:1)
在实际打开或关闭静音之前,我已经设置了静音变量。因此,改变前的脚本会得到的信息。
在 amixer sset Master切换> / dev / null 解决问题之后,将 muted = 行放入 case静音中。在这里:
mute)
amixer sset Master toggle > /dev/null
muted=$(amixer get Master | grep % | cut -d '[' -f 4 | cut -d ']' -f 1 )
if [ $muted == "off" ]; then