Skip to content

Instantly share code, notes, and snippets.

@marciomassari
Created July 10, 2018 21:01
Show Gist options
  • Select an option

  • Save marciomassari/d46a7bafb838f5f13d87df24d454df2f to your computer and use it in GitHub Desktop.

Select an option

Save marciomassari/d46a7bafb838f5f13d87df24d454df2f to your computer and use it in GitHub Desktop.
Script To Set Current Spotify Song As Slack Status
#!/bin/bash
APIKEY="SPOTIFY-API-KEY"
trap onexit INT
function reset() {
echo 'Resetting status'
curl -s -d "payload=$json" "https://slack.com/api/users.profile.set?token="$APIKEY"&profile=%7B%22status_text%22%3A%22%22%2C%22status_emoji%22%3A%22%22%7D" > /dev/null
}
function onexit() {
echo 'Exitting'
reset
exit
}
while true; do
state=$(osascript -e 'tell application "Spotify" to player state')
date
echo "Spotify: "$state
if [[ "$state" != "playing" ]]; then
reset
else
SONG=$(osascript -e 'tell application "Spotify" to artist of current track & " - " & name of current track')
URLSONG=$(echo "$SONG" | perl -MURI::Escape -ne 'chomp;print uri_escape($_),"\n"')
echo $SONG
curl -s -d "payload=$json" "https://slack.com/api/users.profile.set?token="$APIKEY"&profile=%7B%22status_text%22%3A%22"$URLSONG"%20on%20Spotify%22%2C%22status_emoji%22%3A%22%3Aheadphones%3A%22%7D" > /dev/null
fi
sleep 60
done
@marciomassari
Copy link
Copy Markdown
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment