]> git.phdru.name Git - audio-cdr-video.git/blob - audio/pa-volume
Feat(PulseAudio): Get/save volume for different ports
[audio-cdr-video.git] / audio / pa-volume
1 #! /usr/bin/env bash
2 # From http://crunchbanglinux.org/forums/topic/11392/pulseaudio-volume-control-with-media-keys/
3
4 default_sink=`pactl list sinks | awk '/Name:/ {print $2; exit}'`
5 active_port=`pactl list sinks | awk '/Active Port:/ {print $3; exit}'`
6 VOLUME_FILE=~/.config/pulse/volume-$active_port
7 CURVOL=`cat $VOLUME_FILE` # Reads in the current volume
8
9 if [[ $1 == "increase" ]]
10 then
11    CURVOL=$(($CURVOL + 1310)) #1310 is 2% of the total volume (65535), you can change this to suit your needs.
12 fi
13 if [[ $1 == "decrease" ]]
14 then
15    CURVOL=$(($CURVOL - 1310))
16 fi
17 if [[ $1 == "mute" ]]
18 then
19    pactl set-sink-mute "$default_sink" 1
20    exit
21 fi
22 if [[ $1 == "unmute" ]]
23 then
24    pactl set-sink-mute "$default_sink" 0
25    exit
26 fi
27 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)
28 then
29    pactl set-sink-volume "$default_sink" $CURVOL
30    echo $CURVOL > $VOLUME_FILE # Write the new volume to disk to be read the next time the script is run.
31    exit
32 fi