Skip to content

Instantly share code, notes, and snippets.

@scottlee
Forked from jgamblin/slackspotify.sh
Last active October 17, 2018 20:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scottlee/54433e0360722926a26acdf80749f762 to your computer and use it in GitHub Desktop.
Save scottlee/54433e0360722926a26acdf80749f762 to your computer and use it in GitHub Desktop.
A Script To Set Current Spotify Song As Slack Status - MacOS
#!/bin/bash
APIKEY="From Here https://api.slack.com/custom-integrations/legacy-tokens"
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 name of current track & " by " & artist 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%22Listening%20to%3A%20"$URLSONG"%22%2C%22status_emoji%22%3A%22%3Aheadphones%3A%22%7D" > /dev/null
fi
sleep 60
done
@scottlee
Copy link
Author

Updated: Change the wording of the Slack status. Now reads "Listening to: Song by Artist"

Also, make sure to follow the steps called out here.

perl -MCPAN -e shell
install URI::Escape
exit

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