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

40 lines
902 B
Plaintext
Raw Normal View History

#!/bin/sh
######################################################################
# @author : swytch
# @file : AC_notify
# @license : GPLv3
# @created : Wednesday May 20, 2020 17:51:45 CEST
#
# @description : send a notification when AC status change
# refresh statusbar
######################################################################
2020-05-06 03:20:19 +02:00
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