143 lines
4.1 KiB
Plaintext
143 lines
4.1 KiB
Plaintext
|
#!/bin/sh
|
||
|
# speedwm-audioctrl
|
||
|
# This simple shell script handles audio controls for speedwm.
|
||
|
# Run speedwm-audioctrl -help for more information!
|
||
|
# License: GPLv3.
|
||
|
|
||
|
BINDIR=$(cat /usr/share/speedwm-bindir)
|
||
|
|
||
|
MUTE() {
|
||
|
# Mute for pulseaudio/pipewire
|
||
|
if [ "$AUDIO" = "pulse" ]; then
|
||
|
if [ -e "${BINDIR}pulsemixer" ]; then
|
||
|
pulsemixer --toggle-mute
|
||
|
if [ -e "${BINDIR}notify-send" ]; then
|
||
|
if [ "$remute" = "" ]; then
|
||
|
notify-send " Toggled mute"
|
||
|
fi
|
||
|
fi
|
||
|
else
|
||
|
amixer set Master toggle
|
||
|
if [ -e "${BINDIR}notify-send" ]; then
|
||
|
if [ "$remute" = "" ]; then
|
||
|
notify-send " Toggled mute"
|
||
|
fi
|
||
|
fi
|
||
|
fi
|
||
|
fi
|
||
|
}
|
||
|
|
||
|
RAISE() {
|
||
|
if [ "$AUDIO" = "pulse" ]; then
|
||
|
if [ -e "${BINDIR}pulsemixer" ]; then
|
||
|
if [ "$(pulsemixer --get-volume | awk '{ print $1 }')" = "100" ]; then
|
||
|
a=$a
|
||
|
else
|
||
|
pulsemixer --change-volume +7
|
||
|
test ${BINDIR}notify-send && notify-send " $(pulsemixer --get-volume | awk '{ print $1 }')%"
|
||
|
fi
|
||
|
fi
|
||
|
else
|
||
|
if [ "$(amixer -c 0 get Master | tail -n 1 | sed -r "s/.*\[(.*)%\].*/\1/")" = "100" ]; then
|
||
|
a=$a
|
||
|
else
|
||
|
amixer -c 0 set Master 7%+
|
||
|
ls ${BINDIR}notify-send && notify-send " $(amixer -c 0 get Master | tail -n 1 | sed -r "s/.*\[(.*)%\].*/\1/")%"
|
||
|
fi
|
||
|
fi
|
||
|
}
|
||
|
|
||
|
LOWER() {
|
||
|
if [ "$AUDIO" = "pulse" ]; then
|
||
|
if [ -e "${BINDIR}pulsemixer" ]; then
|
||
|
if [ "$(pulsemixer --get-volume | awk '{ print $1 }')" = "0" ]; then
|
||
|
a=$a
|
||
|
else
|
||
|
pulsemixer --change-volume -7
|
||
|
test ${BINDIR}notify-send && notify-send " $(pulsemixer --get-volume | awk '{ print $1 }')%"
|
||
|
fi
|
||
|
|
||
|
fi
|
||
|
else
|
||
|
if [ "$(amixer -c 0 get Master | tail -n 1 | sed -r "s/.*\[(.*)%\].*/\1/")" = "0" ]; then
|
||
|
a=$a
|
||
|
else
|
||
|
amixer -c 0 set Master 7%-
|
||
|
test ${BINDIR}notify-send && notify-send " $(amixer -c 0 get Master | tail -n 1 | sed -r "s/.*\[(.*)%\].*/\1/")%"
|
||
|
fi
|
||
|
fi
|
||
|
}
|
||
|
|
||
|
GETVOL() {
|
||
|
if [ "$AUDIO" = "pulse" ]; then
|
||
|
if [ -e "${BINDIR}pulsemixer" ]; then
|
||
|
echo "$(pulsemixer --get-volume | awk '{ print $1 }')%"
|
||
|
fi
|
||
|
else
|
||
|
echo "$(amixer -c 0 get Master | tail -n 1 | sed -r "s/.*\[(.*)%\].*/\1/")%"
|
||
|
fi
|
||
|
}
|
||
|
|
||
|
GETMUTE() {
|
||
|
if [ "$AUDIO" = "pulse" ]; then
|
||
|
if [ -e "${BINDIR}pulsemixer" ]; then
|
||
|
pulsemixer --get-mute | grep 1 > /dev/null && echo "Muted"
|
||
|
pulsemixer --get-mute | grep 0 > /dev/null && echo "Not muted"
|
||
|
fi
|
||
|
fi
|
||
|
}
|
||
|
|
||
|
SWITCH() {
|
||
|
ls $HOME/.local/share/audioctrl-status || echo "0" > $HOME/.local/share/audioctrl-status
|
||
|
if [ "$(cat $HOME/.local/share/audioctrl-status)" = "0" ]; then
|
||
|
amixer -c 0 sset 'Auto-Mute Mode' Enabled ; echo "1" > $HOME/.local/share/audioctrl-status
|
||
|
if [ -e "${BINDIR}notify-send" ]; then
|
||
|
notify-send " Switched to headphones."
|
||
|
fi
|
||
|
else
|
||
|
amixer -c 0 sset 'Auto-Mute Mode' Disabled ; echo "0" > $HOME/.local/share/audioctrl-status
|
||
|
if [ -e "${BINDIR}notify-send" ]; then
|
||
|
notify-send " Switched to speakers."
|
||
|
fi
|
||
|
fi
|
||
|
}
|
||
|
|
||
|
RUNMIXER() {
|
||
|
if [ "$AUDIO" = "pulse" ]; then
|
||
|
if [ -e "${BINDIR}pulsemixer" ]; then
|
||
|
pulsemixer
|
||
|
elif [ -e "${BINDIR}alsamixer" ]; then
|
||
|
alsamixer
|
||
|
fi
|
||
|
fi
|
||
|
}
|
||
|
|
||
|
AUDIO=$2
|
||
|
case "$2" in
|
||
|
"") AUDIO=alsa
|
||
|
if [ -e "${BINDIR}pulsemixer" ]; then
|
||
|
AUDIO=pulse
|
||
|
fi ;;
|
||
|
esac
|
||
|
|
||
|
# Update status
|
||
|
UPDATESTATUS() {
|
||
|
pkill status && status &
|
||
|
}
|
||
|
|
||
|
case "$1" in
|
||
|
"-mute") MUTE && GETMUTE > /tmp/speedwm-audioctrl-mutestatus ;;
|
||
|
"-remute") remute=true ; MUTE && GETMUTE > /tmp/speedwm-audioctrl-mutestatus ; MUTE && GETMUTE > /tmp/speedwm-audioctrl-mutestatus ; remute="" ; exit 0 ;;
|
||
|
"-raise") RAISE ;;
|
||
|
"-lower") LOWER ;;
|
||
|
"-switch") SWITCH && exit 0 ;;
|
||
|
"-getvol") GETVOL && exit 0 ;;
|
||
|
"-getmute") GETMUTE > /tmp/speedwm-audioctrl-mutestatus && exit 0 ;;
|
||
|
"-getbackend") printf "$AUDIO\n" && exit 0 ;;
|
||
|
"-runmixer") RUNMIXER && exit 0 ;;
|
||
|
"-help") printf "speedwm-audioctrl\n-mute | Toggle mute\n-raise | Raise the volume by 7\n-lower | Lower the volume by 7\n-switch | Toggle output\n-getvol | Get current volume in percentage\n-getmute | Get mute status\n-getbackend | Get audio backend (ALSA, PulseAudio, etc.)\n-runmixer | Run the audio mixer detected on the system\n-remute | Mute and unmute.\n-help | Display this help screen\nNo arguments | Display this help screen\n"; exit 0 ;;
|
||
|
"") $0 -help && exit 0 ;;
|
||
|
esac
|
||
|
|
||
|
pgrep -x status && UPDATESTATUS
|