Skip to content

Instantly share code, notes, and snippets.

@twopoint718
Created November 26, 2019 17:06
Show Gist options
  • Save twopoint718/3c81724ebaf662bc6ac853d5e5be6b43 to your computer and use it in GitHub Desktop.
Save twopoint718/3c81724ebaf662bc6ac853d5e5be6b43 to your computer and use it in GitHub Desktop.
#!/bin/bash
set -e
APIKEY="YOUR-API-KEY-HERE"
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 'Exiting'
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 "“" & name of current track & "” by “" & artist of current track & "”"')
URLSONG=$(echo "$SONG" | perl -MURI::Escape -ne 'chomp;print uri_escape($_),"\n"')
echo "$SONG"
URL="https://slack.com/api/users.profile.set?token=${APIKEY}&profile=%7B%22status_text%22%3A%22Listening%20to%20${URLSONG}%22%2C%22status_emoji%22%3A%22%3Aheadphones%3A%22%7D"
curl -s -d "payload=$json" "$URL" > /dev/null
fi
sleep 60
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment