Created
March 9, 2018 02:20
-
-
Save kfox/bb3a1f8ad6af46ee9eb563844b619c6d to your computer and use it in GitHub Desktop.
Updates your Slack status with the current artist and song title in Spotify
This file contains hidden or 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
#!/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