2012-11-06

Fix【新版】定時調整音量

這裡是定時調整音量新版,說明請看舊版,這次新加入在晚上自動將音量調小前儲存原本音量,過了設定的週期或重新開機時設回原本音量。


Fix Note:
  1. 取得音量錯誤,無法正確儲存音量。
  2. 比對時間錯誤。
Add 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