Last active
July 22, 2018 18:16
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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