From 0af5b4e4df5f827ea25062e613e2bd6ef35b2e77 Mon Sep 17 00:00:00 2001 From: Jonathan Hodgson Date: Sat, 13 Feb 2021 19:05:01 +0000 Subject: [PATCH] Changes the volume script to work with pulseaudio-ctl https://github.com/graysky2/pulseaudio-ctl using amixer is a pain and this takes a lot of the complexity out of it. If pulseaudio-ctl isn't available, the script will still use amixer --- bin/.bin/volume | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/bin/.bin/volume b/bin/.bin/volume index 03a8f51e..57e35039 100755 --- a/bin/.bin/volume +++ b/bin/.bin/volume @@ -24,17 +24,34 @@ function drawBar(){ case "$1" in "up") - amixer -q -D default sset Master 5%+ unmute + if type -p pulseaudio-ctl 2> /dev/null; then + pulseaudio-ctl up + else + amixer -q -D default sset Master 5%+ unmute + fi ;; "down") - amixer -q -D default sset Master 5%- unmute + if type -p pulseaudio-ctl 2> /dev/null; then + pulseaudio-ctl down + else + amixer -q -D default sset Master 5%- unmute + fi ;; "toggle") - amixer -q -D default sset Master toggle + if type -p pulseaudio-ctl 2> /dev/null; then + pulseaudio-ctl mute + else + amixer -q -D default sset Master toggle + fi esac -volume="$(amixer -D default sget Master | grep -o '\[.*\%' | head -n 1 | tr -d '[%')" -speakerStatus="$(amixer -D default sget Master | grep -o '\[\(on\|off\)' | head -n 1 | tr -d '[')" +if type -p pulseaudio-ctl 2> /dev/null; then + volume="$(pulseaudio-ctl full-status | cut -d ' ' -f1)" + speakerStatus="$(pulseaudio-ctl full-status | cut -d ' ' -f2 | sed 's/no/on/g')" +else + volume="$(amixer -D default sget Master | grep -o '\[.*\%' | head -n 1 | tr -d '[%')" + speakerStatus="$(amixer -D default sget Master | grep -o '\[\(on\|off\)' | head -n 1 | tr -d '[')" +fi if [[ "$speakerStatus" == "on" ]]; then