mirror of
https://github.com/arkorty/Scripts.git
synced 2026-03-18 01:07:10 +00:00
Add notification icons to volume and battery
This commit is contained in:
24
battery
24
battery
@@ -8,12 +8,22 @@
|
|||||||
#
|
#
|
||||||
# Copyright (C) 2023 Arkaprabha Chakraborty
|
# Copyright (C) 2023 Arkaprabha Chakraborty
|
||||||
|
|
||||||
last_capacity="NONE"
|
PROG=dunstify
|
||||||
last_status="None"
|
|
||||||
|
|
||||||
|
# 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
|
LOW=20
|
||||||
CRITICAL=10
|
CRITICAL=10
|
||||||
|
|
||||||
|
# status flags
|
||||||
|
last_capacity=NONE
|
||||||
|
last_status=None
|
||||||
|
|
||||||
while true; do
|
while true; do
|
||||||
BATTERY="/sys/class/power_supply/CMB0"
|
BATTERY="/sys/class/power_supply/CMB0"
|
||||||
if [ -d $BATTERY ]; then
|
if [ -d $BATTERY ]; then
|
||||||
@@ -23,22 +33,22 @@ while true; do
|
|||||||
if [ $last_status = "None" ]; then
|
if [ $last_status = "None" ]; then
|
||||||
last_status=$status
|
last_status=$status
|
||||||
elif [ $last_status != "Discharging" ] && [ $status = "Discharging" ]; then
|
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
|
last_status=$status
|
||||||
elif [ $last_status != "Charging" ] && [ $status = "Charging" ]; then
|
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
|
last_status=$status
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ $last_capacity != "FULL" ] && [ $status = "Full" ]; then
|
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"
|
last_capacity="FULL"
|
||||||
elif [ $last_capacity != "LOW" ] && [ $status = "Discharging" ] &&
|
elif [ $last_capacity != "LOW" ] && [ $status = "Discharging" ] &&
|
||||||
[ $capacity -le $LOW ] && [ $capacity -gt $CRITICAL ]; then
|
[ $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
|
last_capacity=LOW
|
||||||
elif [ $status = "Discharging" ] && [ $capacity -le $CRITICAL ]; then
|
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
|
last_capacity=CRITICAL
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|||||||
41
volume
41
volume
@@ -8,17 +8,22 @@
|
|||||||
#
|
#
|
||||||
# Copyright (C) 2023 Arkaprabha Chakraborty
|
# Copyright (C) 2023 Arkaprabha Chakraborty
|
||||||
|
|
||||||
# semicolon separated volume rules for multiple sinks
|
# icon paths
|
||||||
rules="<sink> <volume>;<sink> <volume>;<sink> <volume>"
|
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
|
# semicolon separated volume rule for multiple sinks
|
||||||
step=5 # volume change step
|
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
|
shopt -s lastpipe # run last pipe-element in the shell process
|
||||||
# set max volume for default sink
|
# 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
|
if [ $(pactl get-default-sink) = $(echo $rule | awk '{ print $1 }') ]; then
|
||||||
max=$(echo $rule | awk '{ print $2 }')
|
MAX=$(echo $rule | awk '{ print $2 }')
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
@@ -27,37 +32,37 @@ case $1 in # pattern match option
|
|||||||
pamixer -u # unmute if muted
|
pamixer -u # unmute if muted
|
||||||
|
|
||||||
# set max volume if intended increase step exceeds max volume
|
# set max volume if intended increase step exceeds max volume
|
||||||
if [ $(pamixer --get-volume) -ge $max ]; then
|
if [ $(pamixer --get-volume) -ge $MAX ]; then
|
||||||
pamixer --allow-boost --set-volume $max
|
pamixer --allow-boost --set-volume $MAX
|
||||||
elif [ $(pamixer --get-volume) -le $max ] && [ $(pamixer --get-volume) -ge $((max - step)) ]; then
|
elif [ $(pamixer --get-volume) -le $MAX ] && [ $(pamixer --get-volume) -ge $((MAX - STEP)) ]; then
|
||||||
pamixer --allow-boost --set-volume $max
|
pamixer --allow-boost --set-volume $MAX
|
||||||
else
|
else
|
||||||
pamixer -i $step --allow-boost # increase volume
|
pamixer -i $STEP --allow-boost # increase volume
|
||||||
fi
|
fi
|
||||||
volume=$(pamixer --get-volume) # get current volume
|
volume=$(pamixer --get-volume) # get current volume
|
||||||
|
|
||||||
# send notification with 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)
|
-d)
|
||||||
pamixer -u # unmute if muted
|
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
|
if [ $(pamixer --get-volume) -ge $MAX ]; then
|
||||||
pamixer --allow-boost --set-volume $max
|
pamixer --allow-boost --set-volume $MAX
|
||||||
fi
|
fi
|
||||||
|
|
||||||
volume=$(pamixer --get-volume) # get current volume
|
volume=$(pamixer --get-volume) # get current volume
|
||||||
|
|
||||||
# send notification with 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)
|
-m)
|
||||||
pamixer -t # toggle mute
|
pamixer -t # toggle mute
|
||||||
if $(pamixer --get-mute); then # send notification with mute status
|
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
|
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
|
fi
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|||||||
Reference in New Issue
Block a user