需要幫助製作一個在電池電量不足時通知我的腳本

需要幫助製作一個在電池電量不足時通知我的腳本

我有一個腳本可以顯示 dwmblocks 中的電池百分比,其中我還添加了在電池百分比較低時通知我的功能。但按照我寫的方式,它會不斷發送新的通知,直到費用超過 20。

請注意,該腳本每 5 秒調用一次。

if [ "$bat" -lt 20 ]; then
    echo "$redbg$tfg $ramp20 $bbg$bat%"
    if [ "$status" -e "Discharging" ]; then
        notify-send --urgency=critical "battery low" 
    fi
elif [ "$bat" -lt "40" ]; then
    echo "$ybg$tfg $ramp40 $bbg$bat%"
elif [ "$bat" -lt "60" ]; then
    echo "$ybg$tfg $ramp60 $bbg$bat%"
elif [ "$bat" -lt "70" ]; then
    echo "$ybg$tfg $ramp70 $bbg$bat%"
elif [ "$bat" -lt "90" ]; then
    echo "$gbg$tfg $ramp90 $bbg$bat%"
elif [ "$bat" -le "100" ]; then
    echo "$gbg$tfg $ramp100 $bbg$bat%"
    if [ "$status" -e "Charging" ]; then
        notify-send "battery sufficiently charged" 
    fi
fi

相關內容