From: Oleg Broytman Date: Sun, 7 Jun 2020 00:33:01 +0000 (+0300) Subject: Feat(PulseAudio): Get/save volume for different ports X-Git-Url: https://git.phdru.name/?p=audio-cdr-video.git;a=commitdiff_plain;h=b8ad2e7882014370f6c7c06e1de203d03ccf53af Feat(PulseAudio): Get/save volume for different ports Separate volumes for speakers and headphones. --- diff --git a/audio/pa-bt b/audio/pa-bt index bccd88e..878a5dd 100755 --- a/audio/pa-bt +++ b/audio/pa-bt @@ -1,5 +1,8 @@ #! /bin/sh +active_port=`pactl list sinks | awk '/Active Port:/ {print $3; exit}'` +VOLUME_FILE=~/.config/pulse/volume-$active_port + "`dirname \"$0\"`"/pa-kill sleep 1 pulseaudio -L "module-bluetooth-device address="$1" sink_name=btheadset profile=a2dp" -D && @@ -11,4 +14,4 @@ set-sink-volume btheadset 45858 " | pacmd && echo 0 > "$HOME"/.config/pulse/mute && -echo 45858 > "$HOME"/.config/pulse/volume +echo 45858 > "$HOME"/.config/pulse/$VOLUME_FILE diff --git a/audio/pa-volume b/audio/pa-volume index 90c5acf..56da9a2 100755 --- a/audio/pa-volume +++ b/audio/pa-volume @@ -1,8 +1,10 @@ #! /usr/bin/env bash # From http://crunchbanglinux.org/forums/topic/11392/pulseaudio-volume-control-with-media-keys/ -declare -i CURVOL=`cat ~/.config/pulse/volume` #Reads in the current volume default_sink=`pactl list sinks | awk '/Name:/ {print $2; exit}'` +active_port=`pactl list sinks | awk '/Active Port:/ {print $3; exit}'` +VOLUME_FILE=~/.config/pulse/volume-$active_port +CURVOL=`cat $VOLUME_FILE` # Reads in the current volume if [[ $1 == "increase" ]] then @@ -25,6 +27,6 @@ fi if [[ $CURVOL -ge 0 && $CURVOL -le 65540 ]] # Check to see if the volume is a valid number (65540 was needed in this case because of how I rounded the increment) then pactl set-sink-volume "$default_sink" $CURVOL - echo $CURVOL > ~/.config/pulse/volume # Write the new volume to disk to be read the next time the script is run. + echo $CURVOL > $VOLUME_FILE # Write the new volume to disk to be read the next time the script is run. exit fi