2022-05-27 21:07:07 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
2022-05-28 23:51:20 +02:00
|
|
|
PULSEAUDIO_SINK="${PULSEAUDIO_SINK:-"@DEFAULT_SINK@"}"
|
|
|
|
VOLUME_LIMIT="${VOLUME_LIMIT:-150}"
|
|
|
|
|
|
|
|
TARGET="$1"
|
|
|
|
ADJUSTMENT="$2"
|
|
|
|
|
|
|
|
echo "${TARGET:?} ${ADJUSTMENT:?}" >/dev/null
|
2022-05-27 21:07:07 +02:00
|
|
|
|
|
|
|
function limit_level() {
|
2022-05-28 23:51:20 +02:00
|
|
|
level="$(pactl get-sink-volume "$PULSEAUDIO_SINK" | grep '^Volume' | cut -d' ' -f5 | grep -o "[[:digit:]]*")"
|
2022-05-27 21:07:07 +02:00
|
|
|
|
2022-05-28 23:51:20 +02:00
|
|
|
if [[ "$level" -gt "$VOLUME_LIMIT" ]]; then
|
2022-05-27 21:07:07 +02:00
|
|
|
echo "Limiting volume to: $1"
|
2022-05-28 23:51:20 +02:00
|
|
|
set_level $VOLUME_LIMIT%
|
2022-05-27 21:07:07 +02:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function set_level() {
|
|
|
|
echo "Desired volume adjustment: $1"
|
2022-05-28 23:51:20 +02:00
|
|
|
pactl set-sink-volume "$PULSEAUDIO_SINK" "$1"
|
2022-05-27 21:07:07 +02:00
|
|
|
}
|
|
|
|
|
2022-05-28 23:51:20 +02:00
|
|
|
if [[ "$TARGET" == "volume" ]]; then
|
2022-05-27 21:07:07 +02:00
|
|
|
set_level "$ADJUSTMENT"
|
2022-05-28 23:51:20 +02:00
|
|
|
limit_level "$VOLUME_LIMIT"
|
|
|
|
elif [[ "$TARGET" == "toggle" ]]; then
|
|
|
|
amixer -D pulse sset "$ADJUSTMENT" toggle
|
|
|
|
else
|
|
|
|
echo "Invalid option: $TARGET $ADJUSTMENT"
|
|
|
|
exit 1
|
2022-05-27 21:07:07 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
killall -SIGUSR1 i3status
|