Fix Note:
- 取得音量錯誤,無法正確儲存音量。
- 比對時間錯誤。
- 睡眠週期設定:
_SleepOn=音量調整的開始時間
_SleepOff=音量調整的結束時間
_SleepVolume=調整音量為此設定值
Default Useing:
當22點(晚上10點)先儲存你目前音量,而後從22點(晚上10點)至9點(早上9點)音量調整為85%,於10點後(含)恢復先前所儲存的音量設定。
P.S 設定1點到9點前面不用加0,也就是3點就寫成3不要寫成03,這樣無法比對時間。
#!/bin/bash
_Hour=$(date "+%-H")
_Sound=/var/tmp/sound
_SleepOn=22
_SleepOff=9
_SleepVolume=85%
_SAVE(){
_Mono=$(amixer get Master | grep "Mono:" | awk '{print $4}' | tr -d '[]')
_Front=$(amixer get Master | grep "Front Left:" | awk '{print $5}' | tr -d '[]')
if [ "x${_Front}" != "x" ]
then
_Volume=${_Front}
elif [ "x${_Mono}" != "x" ]
then
_Volume=${_Mono}
else
echo "Unknown Volume"
exit
fi
echo "_Default=${_Volume}" >> ${_Sound}
echo "Save Volume: ${_Volume}"
}
echo "The time now: ${_Hour} "
if [[ -f ${_Sound} && ${_Hour} -le ${_SleepOff} || ${_Hour} -ge ${_SleepOn} ]]
then
echo "Now is Sleep Time Change Volume: ${_SleepVolume}"
amixer sset Master ${_SleepVolume} 1>/dev/null
elif [[ ${_Hour} -le ${_SleepOff} || ${_Hour} -ge ${_SleepOn} ]]
then
_SAVE
echo "Now is Sleep Time Change Volume: ${_SleepVolume}"
amixer sset Master ${_SleepVolume} 1>/dev/null
elif [[ -f ${_Sound} && ${_Hour} -gt ${_SleepOff} && ${_Hour} -lt ${_SleepOn} ]]
then
. ${_Sound}
echo "Now the end of the sleep time to restore the volume: ${_Default}"
amixer sset Master ${_Default} 1>/dev/null
rm -f ${_Sound}
fi