This repository has been archived on 2023-03-02. You can view files and clone it, but cannot push or open issues or pull requests.
dotfiles/.local/bin/AC_notify

31 lines
614 B
Plaintext
Raw Normal View History

2020-05-06 03:20:19 +02:00
#! /bin/sh
# Sends a notification if AC is plugged in (or out)
# Also refreshes statusbar
new_state="$(cat /sys/class/power_supply/AC/online)"
prev_state="$new_state"
notify() { \
# $1 is $new_state
if [ "$1" = 1 ]; then
notify-send -u "normal" "AC plugged in - CHARGING"
else
notify-send -u "critical" "AC unplugged ! - DISCHARGING"
fi
}
update(){ \
new_state="$(cat /sys/class/power_supply/AC/online)"
if [ "$prev_state" != "$new_state" ]; then
notify "$new_state" && refbar
fi
prev_state="$new_state"
}
while :; do
update
# Sleep for 5s seconds before checking again
sleep 5 &
wait
done