Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mattkohl/00a3770ca43f0ca7700ed9b638007597 to your computer and use it in GitHub Desktop.
Save mattkohl/00a3770ca43f0ca7700ed9b638007597 to your computer and use it in GitHub Desktop.
Updates your Slack status with the current artist and song title in Spotify
#!/usr/bin/env bash
: "${SLACK_API_TOKEN:?Need to set SLACK_API_TOKEN environment variable}"
STATUS=$(/usr/bin/osascript <<"EOF"
if application "Spotify" is running and application "Slack" is running then
tell application "Spotify"
set currentArtist to artist of current track as string
set currentSong to name of current track as string
return currentArtist & " - " & currentSong
end tell
else
return "UNKNOWN"
end if
EOF
)
EMOJI=":musical_note:"
if [ "${STATUS}" = "UNKNOWN" ]; then
STATUS=""
EMOJI=""
fi
PAYLOAD='{"profile":{"status_text":"'${STATUS}'","status_emoji":"'${EMOJI}'"}}'
curl \
-H "Content-Type: application/json; charset=utf-8" \
-H "Authorization: Bearer ${SLACK_API_TOKEN}" \
--data "${PAYLOAD}" \
https://slack.com/api/users.profile.set >/dev/null 2>&1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment