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() {
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