#! /usr/bin/env bash # From http://crunchbanglinux.org/forums/topic/11392/pulseaudio-volume-control-with-media-keys/ 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 CURVOL=$(($CURVOL + 1310)) #1310 is 2% of the total volume (65535), you can change this to suit your needs. fi if [[ $1 == "decrease" ]] then CURVOL=$(($CURVOL - 1310)) fi if [[ $1 == "mute" ]] then pactl set-sink-mute "$default_sink" 1 exit fi if [[ $1 == "unmute" ]] then pactl set-sink-mute "$default_sink" 0 exit 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 > $VOLUME_FILE # Write the new volume to disk to be read the next time the script is run. exit fi