#!/bin/sh

# Extract args
vol=$1; shift

# What is left in the args are ALSA device names
while test -n "$1"; do

  # Mute the device if it is on, unmute if it is off
  if amixer get $1 \
    | egrep ': Playback.+\[.+\]$' | grep '\[on\]$' >/dev/null 2>&1; then

    amixer set $1 ${vol} mute

  else

    amixer set $1 ${vol} unmute

  fi

  shift

done

