Add notification icons to volume and battery

This commit is contained in:
2023-10-20 03:48:37 +05:30
parent cf63abc602
commit 4447024a88
2 changed files with 40 additions and 25 deletions

24
battery
View File

@@ -8,12 +8,22 @@
#
# Copyright (C) 2023 Arkaprabha Chakraborty
last_capacity="NONE"
last_status="None"
PROG=dunstify
# icon paths
BATTERY_FULL=/usr/share/icons/Papirus/48x48/status/battery-full.svg
BATTERY_LOW=/usr/share/icons/Papirus/48x48/status/battery-low.svg
BATTERY_CAUTION=/usr/share/icons/Papirus/48x48/status/battery-caution.svg
AC_ADAPTER=/usr/share/icons/Papirus/48x48/status/ac-adapter.svg
# capacity checkpoints
LOW=20
CRITICAL=10
# status flags
last_capacity=NONE
last_status=None
while true; do
BATTERY="/sys/class/power_supply/CMB0"
if [ -d $BATTERY ]; then
@@ -23,22 +33,22 @@ while true; do
if [ $last_status = "None" ]; then
last_status=$status
elif [ $last_status != "Discharging" ] && [ $status = "Discharging" ]; then
notify-send "Power Unplugged" --replace-id 667
$PROG "Power Unplugged" --replace 667 --icon $AC_ADAPTER --timeout 2000
last_status=$status
elif [ $last_status != "Charging" ] && [ $status = "Charging" ]; then
notify-send "Power Plugged" --replace-id 667
$PROG "Power Plugged" --replace 667 --icon $AC_ADAPTER --timeout 2000
last_status=$status
fi
if [ $last_capacity != "FULL" ] && [ $status = "Full" ]; then
notify-send "Battery Full" --replace-id 666
$PROG "Battery Full" --replace 666 --icon $BATTERY_FULL
last_capacity="FULL"
elif [ $last_capacity != "LOW" ] && [ $status = "Discharging" ] &&
[ $capacity -le $LOW ] && [ $capacity -gt $CRITICAL ]; then
notify-send "Battery Low: $capacity%" --replace-id 666
$PROG "Battery Low: $capacity%" --replace 666 --icon $BATTERY_LOW
last_capacity=LOW
elif [ $status = "Discharging" ] && [ $capacity -le $CRITICAL ]; then
notify-send --urgency critical "Battery Critical: $capacity%" --replace-id 666
$PROG --urgency critical "Battery Critical: $capacity%" --replace 666 --icon $BATTERY_CAUTION
last_capacity=CRITICAL
fi
fi

41
volume
View File

@@ -8,17 +8,22 @@
#
# Copyright (C) 2023 Arkaprabha Chakraborty
# semicolon separated volume rules for multiple sinks
rules="<sink> <volume>;<sink> <volume>;<sink> <volume>"
# icon paths
VOLUME_MUTED=/usr/share/icons/Papirus/48x48/status/notification-audio-volume-muted.svg
VOLUME_UNMUTED=/usr/share/icons/Papirus/48x48/status/notification-audio-volume-high.svg
AUDIO_SPEAKER=/usr/share/icons/Papirus/48x48/devices/audio-speakers.svg
max=80 # default max volume
step=5 # volume change step
# semicolon separated volume rule for multiple sinks
RULE="<sink> <volume>;<sink> <volume>;<sink> <volume>"
MAX=80 # default max volume
STEP=5 # volume change step
shopt -s lastpipe # run last pipe-element in the shell process
# set max volume for default sink
echo -e $rules | tr ';' '\n' | while read rule; do
echo -e $RULE | tr ';' '\n' | while read rule; do
if [ $(pactl get-default-sink) = $(echo $rule | awk '{ print $1 }') ]; then
max=$(echo $rule | awk '{ print $2 }')
MAX=$(echo $rule | awk '{ print $2 }')
fi
done
@@ -27,37 +32,37 @@ case $1 in # pattern match option
pamixer -u # unmute if muted
# set max volume if intended increase step exceeds max volume
if [ $(pamixer --get-volume) -ge $max ]; then
pamixer --allow-boost --set-volume $max
elif [ $(pamixer --get-volume) -le $max ] && [ $(pamixer --get-volume) -ge $((max - step)) ]; then
pamixer --allow-boost --set-volume $max
if [ $(pamixer --get-volume) -ge $MAX ]; then
pamixer --allow-boost --set-volume $MAX
elif [ $(pamixer --get-volume) -le $MAX ] && [ $(pamixer --get-volume) -ge $((MAX - STEP)) ]; then
pamixer --allow-boost --set-volume $MAX
else
pamixer -i $step --allow-boost # increase volume
pamixer -i $STEP --allow-boost # increase volume
fi
volume=$(pamixer --get-volume) # get current volume
# send notification with current volume
dunstify -a "volume" -u low -r "9993" -h int:value:"$volume" -i "volume-$1" "Volume: ${volume}%" -t 2000
dunstify -a "volume" -u low -r "9993" -h int:value:"$volume" "Volume: ${volume}%" -t 2000 -i $AUDIO_SPEAKER
;;
-d)
pamixer -u # unmute if muted
pamixer -d $step --allow-boost # decrease volume
pamixer -d $STEP --allow-boost # decrease volume
if [ $(pamixer --get-volume) -ge $max ]; then
pamixer --allow-boost --set-volume $max
if [ $(pamixer --get-volume) -ge $MAX ]; then
pamixer --allow-boost --set-volume $MAX
fi
volume=$(pamixer --get-volume) # get current volume
# send notification with current volume
dunstify -a "volume" -u low -r "9993" -h int:value:"$volume" -i "volume-$1" "Volume: ${volume}%" -t 2000
dunstify -a "volume" -u low -r "9993" -h int:value:"$volume" "Volume: ${volume}%" -t 2000 -i $AUDIO_SPEAKER
;;
-m)
pamixer -t # toggle mute
if $(pamixer --get-mute); then # send notification with mute status
dunstify -i volume-mute -a "volume" -t 2000 -r 9993 -u low "Muted"
dunstify -a "volume" -t 2000 -r 9993 -u low "Muted" -i $VOLUME_MUTED
else
dunstify -i volume-mute -a "volume" -t 2000 -r 9993 -u low "Unmuted"
dunstify -a "volume" -t 2000 -r 9993 -u low "Unmuted" -i $VOLUME_UNMUTED
fi
;;
esac