Closed Nasion-G closed 1 month ago
Try replacing the volume script with this?
#!/usr/bin/env sh
scrDir=$(dirname "$(realpath "$0")")
source $scrDir/globalcontrol.sh
# define functions
print_error() {
cat <<"EOF"
./volumecontrol.sh -[device] <actions>
...valid device are...
i -- input device
o -- output device
p -- player application
...valid actions are...
i -- increase volume [+5]
d -- decrease volume [-5]
m -- mute [x]
EOF
exit 1
}
notify_vol() {
angle="$(((($vol + 2) / 5) * 5))"
ico="${icodir}/vol-${angle}.svg"
bar=$(seq -s "." $(($vol / 15)) | sed 's/[0-9]//g')
notify-send -a "t2" -r 91190 -t 800 -i "${ico}" "${vol}${bar}" "${nsink}"
}
notify_mute() {
mute=$(pamixer "${srce}" --get-mute | cat)
[ "${srce}" == "--default-source" ] && dvce="mic" || dvce="speaker"
if [ "${mute}" == "true" ]; then
notify-send -a "t2" -r 91190 -t 800 -i "${icodir}/muted-${dvce}.svg" "muted" "${nsink}"
else
notify-send -a "t2" -r 91190 -t 800 -i "${icodir}/unmuted-${dvce}.svg" "unmuted" "${nsink}"
fi
}
action_pamixer() {
pamixer "${srce}" -"${1}" "${step}"
vol=$(pamixer "${srce}" --get-volume | cat)
}
action_playerctl() {
[ "${1}" == "i" ] && pvl="+" || pvl="-"
playerctl --player="${srce}" volume 0.0"${step}""${pvl}"
vol=$(playerctl --player="${srce}" volume | awk '{ printf "%.0f\n", $0 * 100 }')
}
select_output() {
if [ "$@" ]; then
desc="$*"
device=$(pactl list sinks | grep -C2 -F "Description: $desc" | grep Name | cut -d: -f2 | xargs)
if pactl set-default-sink "$device"; then
notify-send -t 2000 -r 2 -u low "Activated: $desc"
else
notify-send -t 2000 -r 2 -u critical "Error activating $desc"
fi
else
pactl list sinks | grep -ie "Description:" | awk -F ': ' '{print $2}' | sort |
while IFS= read -r x; do echo "$x"; done
fi
}
# eval device option
while getopts iop:s: DeviceOpt; do
case "${DeviceOpt}" in
i)
nsink=$(pamixer --list-sources | awk -F '"' 'END {print $(NF - 1)}')
[ -z "${nsink}" ] && echo "ERROR: Input device not found..." && exit 0
ctrl="pamixer"
srce="--default-source"
;;
o)
nsink=$(pamixer --get-default-sink | awk -F '"' 'END{print $(NF - 1)}')
[ -z "${nsink}" ] && echo "ERROR: Output device not found..." && exit 0
ctrl="pamixer"
srce=""
;;
p)
nsink=$(playerctl --list-all | grep -w "${OPTARG}")
[ -z "${nsink}" ] && echo "ERROR: Player ${OPTARG} not active..." && exit 0
ctrl="playerctl"
srce="${OPTARG}" # Use OPTARG directly
;;
s)
default_sink="$(pamixer --get-default-sink | awk -F '"' 'END{print $(NF - 1)}')"
export selected_sink="$(select_output "${@}" | rofi -dmenu -select "${default_sink}" -config "${confDir}/rofi/notification.rasi")"
select_output "$selected_sink"
exit
;;
*) print_error ;;
esac
done
# set default variables
icodir="${confDir}/dunst/icons/vol"
shift $((OPTIND - 1))
step="${2:-5}"
# execute action
case "${1}" in
i) action_${ctrl} i ;;
d) action_${ctrl} d ;;
m) "${ctrl}" "${srce}" -t && notify_mute && exit 0 ;;
*) print_error ;;
esac
notify_vol
Works perfectly now. Thanks mate!
Bug Report
Description
I was checking waybar's config.jsonc and I saw that using mouse wheel up/down on
custom/spotify
is supposed to increase/decrease volume on spotify, but that is not happening. Upon further investigation, runningvolumecontrol.sh -p spotify i
orvolumecontrol.sh -p spotify d
givesERROR: Player not active...
. This is false because runningplayerctl --list-all
(as specified on line 83 of volumecontrol.sh) showsspotify
(and I can confirm it is actually playing cause I am listening to it). I changed${OPTARG}
(in line 83 column 49) tospotify
to see if it would fix it. Now when I runvolumecontrol.sh -p spotify i
(orvolumecontrol.sh -p spotify d
for that matter) it does not showERROR: Player not active...
anymore, but just prints out:(Volume control for input/output devices does work by the way, just spotify doesn't)
Steps to Reproduce
No idea why this is happening.
Expected Behavior
Scrolling with mouse wheel on Waybar's
custom/spotify
should increase/decrease volume of spotify. And also using volumecontrol.sh via cli for changing spotify's volume should also work.Actual Behavior
Gives out
ERROR: Player not active...
, and by changing${OPTARG}
on line 83 it just prints the default error message.Environment
Linux Arch 6.9.9-273linux-tkg #1 SMP PREEMPT_DYNAMIC TKG Thu, 11 Jul 2024 21:38:19 +0000 x86_64 GNU/Linux