Last active
August 29, 2015 14:00
-
-
Save Gordin/c84691470af78ea602ef to your computer and use it in GitHub Desktop.
This sets the volume of the default pulseaudio sink and all currently running applications to the a certain value (0-100). If you call this without a value, all applications will be reset to the volume of the default sink.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
reset_volumes() { | |
volume=$(pacmd dump-volumes | head -1 | sed 's/.\+: \([0-9]\+\).*real.*/\1/') | |
apps=($(pacmd list-sink-inputs | grep index | cut -d " " -f 6)) | |
for app in $apps; do | |
pacmd set-sink-input-volume ${app} ${volume} | |
done | |
} | |
set_volume() { | |
vol=$(( ( 65536 * $1 / 100 ) + 1 )) | |
pacmd set-sink-volume 0 ${vol} | |
reset_volumes | |
} | |
if [[ -n $1 ]]; then | |
# WARNING: pulseaudio/pacmd has no (sensible) upper bounds for volume, | |
# so if you remove the following checks, ./volume 10000 will probably | |
# destroy your speakers and/or your ears. | |
if (( $1 > 100 )); then | |
set_volume 100 | |
elif (( $1 <= 0 )); then | |
set_volume 0 | |
else | |
set_volume $1 | |
fi | |
else | |
reset_volumes | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment