Skip to content

Instantly share code, notes, and snippets.

@josteinaj
Last active July 22, 2018 18:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save josteinaj/09e0d87c8ea5402ae914c801a1c77b6f to your computer and use it in GitHub Desktop.
Save josteinaj/09e0d87c8ea5402ae914c801a1c77b6f to your computer and use it in GitHub Desktop.
Wrapper for the ["socos" Sonos CLI](https://github.com/soco/socos) for using speaker names instead of IPs
#!/bin/bash
SOCOS="/home/pi/.local/bin/socos"
NAME="$1"
shift
COMMAND="$1"
shift
if [ "$NAME" = "" ]; then
echo "Missing first argument: Sonos spaker name"
exit 1
fi
if [ "$COMMAND" = "" ]; then
echo "Missing second argument: command to send to speaker"
exit 1
fi
IP=""
while read speaker; do
SPEAKER_IP="`echo $speaker | awk '{print $2}'`"
SPEAKER_NAME="`echo $speaker | awk '{$1=""; $2=""; print}' | sed 's/^ *//'`"
if [ "$SPEAKER_NAME" = "$NAME" ]; then
IP="$SPEAKER_IP"
fi
done <<< "$($SOCOS list)"
if [ "$IP" = "" ]; then
echo "Could not find a speaker named '$NAME'"
exit 1
fi
$SOCOS $COMMAND $IP "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment