31 lines
614 B
Plaintext
31 lines
614 B
Plaintext
|
#! /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
|