Created
December 4, 2016 15:31
-
-
Save demaisj/462da207e0c1fda95a3e6e143b39df3b to your computer and use it in GitHub Desktop.
Low Battery Alert
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# TO BE RUN EACH 5 MINUTES | |
# | |
BATTERY="/sys/class/power_supply/BAT0" | |
CRITICAL=10 | |
ICON="battery-caution" | |
NOT_CHARGING="Discharging" | |
battery_status=$(cat "$BATTERY/status") | |
battery_level=$(echo "define trunc(x){auto s;s=scale;scale=0;x=x/1;scale=s;return x};trunc($(cat "$BATTERY/charge_now")/$(cat "$BATTERY/charge_full")*100)" | bc -l) | |
export DISPLAY=:1.0 | |
if [ -r "$HOME/.dbus/Xdbus" ]; then | |
. "$HOME/.dbus/Xdbus" | |
fi | |
if [ $battery_level -le $CRITICAL -a $battery_status = $NOT_CHARGING ] | |
then | |
echo "Battery low" | |
/usr/bin/notify-send -u critical -i $ICON -t 10000 "Battery is low" "Only ${battery_level}% remaining!" | |
/usr/bin/paplay "$HOME/.local/share/sounds/ui/LowBattery.ogg" | |
else | |
echo "Battery not low" | |
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# TO BE RUN AT LOGIN | |
# | |
mkdir -p $HOME/.dbus | |
chmod 755 $HOME/.dbus | |
touch $HOME/.dbus/Xdbus | |
chmod 600 $HOME/.dbus/Xdbus | |
env | grep DBUS_SESSION_BUS_ADDRESS > $HOME/.dbus/Xdbus | |
env | grep XAUTHORITY>> $HOME/.dbus/Xdbus | |
env | grep XDG_RUNTIME_DIR>> $HOME/.dbus/Xdbus | |
echo 'export DBUS_SESSION_BUS_ADDRESS' >> $HOME/.dbus/Xdbus | |
echo 'export XAUTHORITY' >> $HOME/.dbus/Xdbus | |
echo 'export XDG_RUNTIME_DIR' >> $HOME/.dbus/Xdbus | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment