]> git.armaanb.net Git - bin.git/commitdiff
Audio-set: Add script. Volume change script for WM
authorArmaan Bhojwani <me@armaanb.net>
Fri, 29 Jan 2021 02:54:30 +0000 (21:54 -0500)
committerArmaan Bhojwani <me@armaanb.net>
Fri, 29 Jan 2021 02:54:30 +0000 (21:54 -0500)
Instead of calling pactl or amixer directly, you can use this script.
The advantage is that this script checks whether the sound is muted,
and unmutes it for you when you change the volume, more closely
mimicking the behavior of most desktop environments. It also sends a
notification with the current audio status. This implementation relies
on amixer and pulseaudio, although could easily work with an alsa-only
setup if that's your thing, just by replacing the pactl commands with
amixer (or any other alsa mixer) commands.

audio-set [new file with mode: 0755]

diff --git a/audio-set b/audio-set
new file mode 100755 (executable)
index 0000000..572bdf5
--- /dev/null
+++ b/audio-set
@@ -0,0 +1,12 @@
+#!/usr/bin/env bash
+# When changing volume, if muted, unmute
+
+if [[ ${1} ]]; then
+  [[ $(amixer sget Master | tail -n 1 | grep "off") ]] &&
+    pactl set-sink-mute 0 toggle
+  pactl set-sink-volume 0 ${1}%
+else
+  pactl set-sink-mute 0 toggle
+fi
+
+notify-send "Volume" "$(amixer sget Master | tail -n 1)" -t 1000