Skip to content

Instantly share code, notes, and snippets.

@wolfg1969
Last active April 19, 2025 13:00
Show Gist options
  • Save wolfg1969/cfa4078853acdce3ffa75bb24c1c0324 to your computer and use it in GitHub Desktop.
Save wolfg1969/cfa4078853acdce3ffa75bb24c1c0324 to your computer and use it in GitHub Desktop.
A bash script to mute/unmute as GPIO button command of moOde Audio Player
#!/bin/bash
if [ ! -f /var/log/mute_unmute.lock ]; then # avoid running twice in the debounce time
touch /var/log/mute_unmute.lock
else
exit 0
fi
volume=$(mpc status | grep volume | awk '{print $2}')
vol=${volume::-1}
if [ "$vol" != "0" ]; then
echo $vol > /tmp/last_vol
mpc volume 0
else
last_vol=$(cat /tmp/last_vol 2>/dev/null | echo 50)
mpc volume $last_vol
fi
sleep 1.5 # great than the debounce time (which is 1000ms by default)
rm /var/log/mute_unmute.lock
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment