commit c88112fa5e22a7974a5968c4f1c7d8992ede938c parent 5032a417724cbb6311d7bba6b9f74cce31aeb9bd Author: Jacob R. Edwards <jacob@jacobedwards.org> Date: Mon, 27 Feb 2023 09:33:57 -0800 Update the vol script and add a mute script The vol script is functionally identical (except that it displays an error if too many arguments are given), but uses bc(1) instead of hoc(1). The new mute script uses vol to elegantly mute and unmute the system's audio. Diffstat:
| A | local/bin/bin/mute | | | 12 | ++++++++++++ |
| M | local/bin/bin/vol | | | 27 | +++++++++++++++++---------- |
2 files changed, 29 insertions(+), 10 deletions(-)
diff --git a/local/bin/bin/mute b/local/bin/bin/mute @@ -0,0 +1,12 @@ +#!/bin/sh +# Copyright 2023 Jacob R. Edwards <jacob@jacobedwards.org> +# Mute and unmute audio + +if vol | awk '$2 == 0 { exit 1 }' +then + vol 0 > /tmp/unmute +elif test -f /tmp/unmute +then + sh /tmp/unmute > /dev/null + rm /tmp/unmute +fi diff --git a/local/bin/bin/vol b/local/bin/bin/vol @@ -1,12 +1,19 @@ #!/bin/sh -# Copyright 2021 Jacob R. Edwards -# Hoc should be replaced by bc (I don't understand the scale variable) +# Copyright 2021, 2023 Jacob R. Edwards <jacob@jacobedwards.org> +# Control audio output levels -vol=$(hoc -e "int($(sndioctl -n output.level)*100)") -if test $# -gt 0 -then - sign=${1%%[!+-]*} - num=${1#[+-]} - sndioctl -q output.level=$sign$(hoc -e "$num/100") -fi -echo vol $vol +vol() sndioctl -${1:+q}n output.level"${1:+=$1}" + +ovol=$(bc -e "$(vol)*100" < /dev/null | cut -d. -f1) +case $# in +(0) ;; +(1) + s="${1%%[!+-]*}" + n="${1#[+-]}" + vol $s$(bc -e scale=2 -e "$n/100" < /dev/null) + ;; +(*) + echo "usage: ${0##*/} [[+-]vol]" 1>&2 + exit 1 +esac +echo vol $ovol