|
|
|
@ -1,43 +1,33 @@
|
|
|
|
|
#!/bin/bash
|
|
|
|
|
CACHE_DIR="$HOME/.cache/audio-control"
|
|
|
|
|
|
|
|
|
|
[ "$#" -eq 0 ] &&
|
|
|
|
|
echo "Requires a command. Run with 'help' for a list of commands." &&
|
|
|
|
|
exit 1
|
|
|
|
|
[ "$#" -gt 1 ] &&
|
|
|
|
|
echo "Too many arguments. Run with 'help' for a list of commands." &&
|
|
|
|
|
exit 1
|
|
|
|
|
|
|
|
|
|
[ -d $CACHE_DIR ] ||
|
|
|
|
|
mkdir -p $CACHE_DIR
|
|
|
|
|
|
|
|
|
|
query_outport() {
|
|
|
|
|
active_port="$(pactl list sinks | grep 'Active Port')"
|
|
|
|
|
if [[ $active_port == *"speaker"* ]]
|
|
|
|
|
if [ "$#" -eq 0 ]
|
|
|
|
|
then
|
|
|
|
|
echo "SPK" > $CACHE_DIR/port
|
|
|
|
|
else
|
|
|
|
|
echo "HDF" > $CACHE_DIR/port
|
|
|
|
|
echo "Requires a command. Run with 'help' for a list of commands."
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
if [ "$#" -gt 1 ]
|
|
|
|
|
then
|
|
|
|
|
echo "Too many arguments. Run with 'help' for a list of commands."
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
pactl list sinks | awk '/Mute/ { if ($2 == "no") print "VOL"; else print "MUT"; }' > $CACHE_DIR/vol_status
|
|
|
|
|
pactl list sinks | grep '^[[:space:]]Volume:' | head -n $(( $SINK + 1 )) | tail -n 1 | sed -e 's,.* \([0-9][0-9]*\)%.*,\1,' > $CACHE_DIR/vol_level
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case $1 in
|
|
|
|
|
"mute")
|
|
|
|
|
pactl set-sink-mute 0 toggle
|
|
|
|
|
pactl list sinks | awk '/Mute/ { if ($2 == "no") print "VOL"; else print "MUT"; }' > $CACHE_DIR/vol_status;;
|
|
|
|
|
pactl list sinks | awk '/Mute/ { if ($2 == "no") print "VOL"; else print "MUT"; }'
|
|
|
|
|
;;
|
|
|
|
|
"vol-up")
|
|
|
|
|
pactl set-sink-volume 0 +5%
|
|
|
|
|
pactl list sinks | grep '^[[:space:]]Volume:' | head -n $(( $SINK + 1 )) | tail -n 1 | sed -e 's,.* \([0-9][0-9]*\)%.*,\1,' > $CACHE_DIR/vol_level;;
|
|
|
|
|
pactl list sinks | grep '^[[:space:]]Volume:' | head -n $(( SINK + 1 )) | tail -n 1 | sed -e 's,.* \([0-9][0-9]*\)%.*,\1,'
|
|
|
|
|
;;
|
|
|
|
|
"vol-down")
|
|
|
|
|
pactl set-sink-volume 0 -5%
|
|
|
|
|
pactl list sinks | grep '^[[:space:]]Volume:' | head -n $(( $SINK + 1 )) | tail -n 1 | sed -e 's,.* \([0-9][0-9]*\)%.*,\1,' > $CACHE_DIR/vol_level;;
|
|
|
|
|
pactl list sinks | grep '^[[:space:]]Volume:' | head -n $(( SINK + 1 )) | tail -n 1 | sed -e 's,.* \([0-9][0-9]*\)%.*,\1,'
|
|
|
|
|
;;
|
|
|
|
|
"reset")
|
|
|
|
|
pactl set-sink-volume 0 50%
|
|
|
|
|
pactl list sinks | grep '^[[:space:]]Volume:' | head -n $(( $SINK + 1 )) | tail -n 1 | sed -e 's,.* \([0-9][0-9]*\)%.*,\1,' > $CACHE_DIR/vol_level;;
|
|
|
|
|
"toggle-port")
|
|
|
|
|
query_outport;;
|
|
|
|
|
pactl list sinks | grep '^[[:space:]]Volume:' | head -n $(( SINK + 1 )) | tail -n 1 | sed -e 's,.* \([0-9][0-9]*\)%.*,\1,'
|
|
|
|
|
;;
|
|
|
|
|
"help")
|
|
|
|
|
echo "USAGE: audio-control <command>
|
|
|
|
|
|
|
|
|
|