home · contact · privacy
Further improve volume setting script.
authorChristian Heller <c.heller@plomlompom.de>
Fri, 21 Mar 2025 13:56:58 +0000 (14:56 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Fri, 21 Mar 2025 13:56:58 +0000 (14:56 +0100)
testing/home/desktop/.local/bin/vol

index 2872d915d12419a662c169f083c01705ff043244..ddc5598450043fcfbdcf7165bc66bdbb11c63d77 100755 (executable)
@@ -11,8 +11,8 @@ print_usage() {
     echo "Usage: ${BIN_NAME} [${FLAG_HELP_SHORT}] [${FLAG_HELP_LONG}] [LOUDNESS]"
     echo "Set audio volume, or (if called without any arguments) toggle audio device muteness.\n"
     echo "Available arguments (of which at most one may be used):\n"
-    echo "  LOUDNESS  audio volume to set (as percentage, must be integer)"
-    echo "  ${FLAG_HELP_SHORT}, ${FLAG_HELP_LONG}   display this help and exit"
+    echo "  LOUDNESS\taudio volume to set (as percentage, must be integer)"
+    echo "  ${FLAG_HELP_SHORT}, ${FLAG_HELP_LONG}\tdisplay this help and exit"
 }
 
 error_exit() {
@@ -21,23 +21,33 @@ error_exit() {
     exit 1
 }
 
+dev_is_mute() {
+    [ "$(pactl get-sink-mute 0)" = "Mute: yes" ]
+}
+
 toggle_mute() {
-    if [ "$(pactl get-sink-mute 0)" = "Mute: no" ]; then
-        MUTE_BOOL=1
-    else
+    if dev_is_mute; then
         MUTE_BOOL=0
+        MUTE_WORD=off
+    else
+        MUTE_BOOL=1
+        MUTE_WORD=on
     fi
     pacmd set-sink-mute 0 "${MUTE_BOOL}"
+    echo "Toggled audio device muteness ${MUTE_WORD}."
 }
 
 set_vol_percentage() {
     AT_FULL=65536
     pacmd set-sink-volume 0 $(calc "($1 * ${AT_FULL} // 100)")
+    echo -n "Audio volume set to ${1}%."
+    dev_is_mute && echo -n " (But audio device is muted.)"
+    echo
 }
 
 N_MAX_ARGS=1
 if [ "$#" -gt "${N_MAX_ARGS}" ]; then
-    error_exit "number of arguments greater ${N_MAX_ARGS}"
+    error_exit "number of arguments greater ${N_MAX_ARGS}."
 elif [ -z "$1" ]; then
     toggle_mute
 elif [ -z "$(echo -n $1 | sed 's/[0-9]*//g')" ]; then