]> git.phdru.name Git - audio-cdr-video.git/blob - audio/pa-volume
Feat(PulseAudio): Get the default sink dynamically
[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 declare -i CURVOL=`cat ~/.config/pulse/volume` #Reads in the current volume
5 default_sink=`pactl list sinks | awk '/Name:/ {print $2; exit}'`
6
7 if [[ $1 == "increase" ]]
8 then
9    CURVOL=$(($CURVOL + 1310)) #1310 is 2% of the total volume (65535), you can change this to suit your needs.
10 fi
11 if [[ $1 == "decrease" ]]
12 then
13    CURVOL=$(($CURVOL - 1310))
14 fi
15 if [[ $1 == "mute" ]]
16 then
17    pactl set-sink-mute "$default_sink" 1
18    exit
19 fi
20 if [[ $1 == "unmute" ]]
21 then
22    pactl set-sink-mute "$default_sink" 0
23    exit
24 fi
25 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)
26 then
27    pactl set-sink-volume "$default_sink" $CURVOL
28    echo $CURVOL > ~/.config/pulse/volume # Write the new volume to disk to be read the next time the script is run.
29    exit
30 fi