2021-11-04 15:56:01 +01:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
set -euo pipefail
|
|
|
|
|
2021-11-12 10:17:39 +01:00
|
|
|
NOTIFY=(
|
|
|
|
notify-send
|
|
|
|
-u low
|
|
|
|
-h string:x-canonical-private-synchronous:change-audio
|
|
|
|
)
|
|
|
|
|
|
|
|
do_change_volume() {
|
2022-02-18 12:12:29 +01:00
|
|
|
local args=()
|
|
|
|
|
2021-11-12 10:17:39 +01:00
|
|
|
if [ "$1" = "up" ]; then
|
2022-02-18 12:12:29 +01:00
|
|
|
args+=("-i")
|
2021-11-12 10:17:39 +01:00
|
|
|
else
|
2022-02-18 12:12:29 +01:00
|
|
|
args+=("-d")
|
|
|
|
fi
|
|
|
|
shift
|
|
|
|
|
|
|
|
# Do not boost over 100% unless explitily asked for
|
|
|
|
if [ "$1" = "--force" ] || [ "$1" = "-f" ]; then
|
|
|
|
args=("--allow-boost" "${args[@]}")
|
|
|
|
shift
|
2021-11-12 10:17:39 +01:00
|
|
|
fi
|
|
|
|
|
2022-02-18 12:12:29 +01:00
|
|
|
# Volume
|
|
|
|
args+=("$1")
|
|
|
|
|
|
|
|
pamixer "${args[@]}"
|
|
|
|
|
2021-11-12 10:17:39 +01:00
|
|
|
newVolume="$(pamixer --get-volume || true)"
|
|
|
|
[ "$(pamixer --get-volume-human)" = "muted" ] && isMuted=true
|
|
|
|
|
|
|
|
MSG="Set volume to $newVolume%"
|
|
|
|
if [ "${isMuted:-false}" = true ]; then
|
|
|
|
MSG="$MSG (muted)"
|
|
|
|
fi
|
|
|
|
"${NOTIFY[@]}" \
|
|
|
|
-h "int:value:$newVolume" \
|
|
|
|
-- "$MSG"
|
|
|
|
}
|
|
|
|
|
|
|
|
do_toggle() {
|
2022-02-18 12:12:29 +01:00
|
|
|
local args=()
|
2021-11-12 10:17:39 +01:00
|
|
|
if [ "${2:-audio}" = mic ]; then
|
|
|
|
args+=(--default-source)
|
|
|
|
MSG="Toggled microphone"
|
|
|
|
else
|
|
|
|
MSG="Toggled audio output"
|
|
|
|
fi
|
|
|
|
|
|
|
|
pamixer "${args[@]}" --toggle-mute
|
|
|
|
|
|
|
|
if [ "$(pamixer "${args[@]}" --get-mute)" = true ]; then
|
|
|
|
MSG="$MSG (muted)"
|
|
|
|
else
|
|
|
|
MSG="$MSG (unmuted)"
|
|
|
|
fi
|
|
|
|
|
|
|
|
"${NOTIFY[@]}" -- "$MSG"
|
|
|
|
}
|
|
|
|
|
|
|
|
case "$1" in
|
|
|
|
up|down)
|
|
|
|
do_change_volume "$@"
|
|
|
|
;;
|
|
|
|
toggle)
|
|
|
|
do_toggle "$@"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "No suche option '$1'" >&2
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|