mirror of
https://github.com/arkorty/Scripts.git
synced 2026-03-18 01:07:10 +00:00
70 lines
2.2 KiB
Bash
Executable File
70 lines
2.2 KiB
Bash
Executable File
#!/usr/bin/sh
|
|
|
|
# Script: volume
|
|
# License: MIT
|
|
# Author: Arkaprabha Chakraborty
|
|
# Created: 27-9-23
|
|
# Dependencies: pipewire-pulseaudio, pamixer, dunstify
|
|
#
|
|
# Copyright (C) 2023 Arkaprabha Chakraborty
|
|
|
|
# icon paths
|
|
ICON_DIR=/usr/share/icons/<ICON_PACK>
|
|
VOLUME_MUTED=$ICON_DIR/48x48/status/notification-audio-volume-muted.svg
|
|
VOLUME_UNMUTED=$ICON_DIR/48x48/status/notification-audio-volume-high.svg
|
|
AUDIO_SPEAKER=$ICON_DIR/48x48/devices/audio-speakers.svg
|
|
|
|
# semicolon separated volume rule for multiple sinks
|
|
RULE="<sink> <volume>;<sink> <volume>;<sink> <volume>"
|
|
|
|
MAX=100 # 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 $RULE | tr ';' '\n' | while read rule; do
|
|
if [ $(pactl get-default-sink) = $(echo $rule | awk '{ print $1 }') ]; then
|
|
MAX=$(echo $rule | awk '{ print $2 }')
|
|
fi
|
|
done
|
|
|
|
case $1 in # pattern match option
|
|
-i)
|
|
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
|
|
else
|
|
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" "Volume: ${volume}%" -t 2000 -i $AUDIO_SPEAKER
|
|
;;
|
|
-d)
|
|
pamixer -u # unmute if muted
|
|
pamixer -d $STEP --allow-boost # decrease volume
|
|
|
|
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" "Volume: ${volume}%" -t 2000 -i $AUDIO_SPEAKER
|
|
;;
|
|
-m)
|
|
pamixer -t # toggle mute
|
|
if $(pamixer --get-mute); then # send notification with mute status
|
|
dunstify -a "volume" -t 2000 -r 9993 -u low "Muted" -i $VOLUME_MUTED
|
|
else
|
|
dunstify -a "volume" -t 2000 -r 9993 -u low "Unmuted" -i $VOLUME_UNMUTED
|
|
fi
|
|
;;
|
|
esac
|