../pulseaudio-setting-volume-from-command-line

Pulseaudio: setting volume from command line

Update

Due to the very kind feedback and nice improvements i rewrote it a bit. (mainly copy and pasted it from the messages i received) :)

I did not add the unmute function to the plus and minus calls as ettam suggested in the comments. coz i dont want this for various reasons. i understand that this is usefull for most ppl.

https://github.com/boredomwontgetus/pa-vol

Usage:

get it from github

git clone https://github.com/boredomwontgetus/pa-vol.git

increase volume by $VOL_STEP

./pa-vol.sh plus

decrease volume by $VOL_STEP

./pa-vol.sh minus

mute

./pa-vol.sh mute

get fancy volumen bar

./pa-vol.sh get

Thanks to everybody who commented and improved the script a bit.

Outdated

This script is the original(old/outdated) version. its just kept here for reference reasons.

A quick shell script to in/decrease (and mute) my pulseaudio device.

#!/bin/bash

SINK_NAME="alsa_output.pci-0000_00_1b.0.analog-stereo"
VOL_STEP="0x01000"

VOL_NOW=`pacmd dump | grep -P "^set-sink-volume $SINK_NAME\s+" | perl -p -i -e 's/.+\s(.x.+)$/$1/'`

case "$1" in
	plus)
	VOL_NEW=$((VOL_NOW + VOL_STEP))
	if [ $VOL_NEW -gt $((0x10000)) ]
	then
		VOL_NEW=$((0x10000))
	fi
	pactl set-sink-volume $SINK_NAME `printf "0x%X" $VOL_NEW`

	;;
	minus)
	VOL_NEW=$((VOL_NOW - VOL_STEP))
	if [ $(($VOL_NEW)) -lt $((0x00000)) ]
	then
		VOL_NEW=$((0x00000))
	fi
	pactl set-sink-volume $SINK_NAME `printf "0x%X" $VOL_NEW`
	;;
	mute)

	MUTE_STATE=`pacmd dump | grep -P "^set-sink-mute $SINK_NAME\s+" | perl -p -i -e 's/.+\s(yes|no)$/$1/'`
	if [ $MUTE_STATE = no ]
	then
	        pactl set-sink-mute $SINK_NAME 1
	elif [ $MUTE_STATE = yes ]
	then
		pactl set-sink-mute $SINK_NAME 0
	fi
esac

Usage:

copy and paste it to pa-vol.sh. chmod it executeable. change the $SINK_NAME to your device name.

increase volume by $VOL_STEP

./pa-vol.sh plus

decrease volume by $VOL_STEP

./pa-vol.sh minus

mute

./pa-vol.sh mute