{"id":23763617,"url":"https://github.com/tomashubelbauer/spotify-slack-status","last_synced_at":"2025-07-19T10:33:57.844Z","repository":{"id":107986269,"uuid":"584902050","full_name":"TomasHubelbauer/spotify-slack-status","owner":"TomasHubelbauer","description":"A script for setting the currently playing Spotify song as your Slack status","archived":false,"fork":false,"pushed_at":"2023-01-10T20:58:19.000Z","size":38,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-06-01T16:38:59.261Z","etag":null,"topics":["slack","slack-app","slack-status","spotify"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/TomasHubelbauer.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2023-01-03T20:12:05.000Z","updated_at":"2024-08-29T13:40:18.000Z","dependencies_parsed_at":"2023-05-15T00:15:21.479Z","dependency_job_id":null,"html_url":"https://github.com/TomasHubelbauer/spotify-slack-status","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/TomasHubelbauer/spotify-slack-status","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TomasHubelbauer%2Fspotify-slack-status","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TomasHubelbauer%2Fspotify-slack-status/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TomasHubelbauer%2Fspotify-slack-status/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TomasHubelbauer%2Fspotify-slack-status/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TomasHubelbauer","download_url":"https://codeload.github.com/TomasHubelbauer/spotify-slack-status/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TomasHubelbauer%2Fspotify-slack-status/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265916902,"owners_count":23848810,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["slack","slack-app","slack-status","spotify"],"created_at":"2024-12-31T22:13:08.684Z","updated_at":"2025-07-19T10:33:57.832Z","avatar_url":"https://github.com/TomasHubelbauer.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Spotify Slack Status\n\nThis script will set your Slack status to the current song playing in Spotify\nand update it every 10 seconds as long as your Slack status is empty or set to\n`:headphones:`.\nIt will not overwrite your Slack status if you set your own status.\n\n```sh\n# Make sure these prerequisites are met in order for this script to work\n# - macOS\n# - jq (`brew install jq`)\n# - Spotify\n\n# Find the directory the script is in for relative access to `slack.pat`\n# Note that this is required when running as a login item which starts in `~`\nDIR=$(dirname \"$(readlink -f -- \"$0\")\")\n\n# Get this token by:\n# - Creating a Slack app https://api.slack.com/apps\n# - Go to Permissions \u003e Scopes \u003e User Token Scopes\n# - Add `users.profile:write` for the status update Slack API call\n# - Add `users.profile:read` for the :headphones: current status emoji check\n# - Scroll up and select Install to Workspace under OAuth Tokens for Your Workspace\n# - Copy User OAuth Token under OAuth Tokens for Your Workspace\nTOKEN=$(cat $DIR/slack.pat)\n\n# Configure the delay between the Spotify checks and Slack status updates\nDELAY=10\n\nwhile true\ndo\n  # Bail if Slack status is already set and is not `:headphones:`\n  EMOJI=$(curl -H \"Authorization: Bearer $TOKEN\" --no-progress-meter https://slack.com/api/users.profile.get | jq --raw-output '.profile.status_emoji')\n  if [ -n \"$EMOJI\" ];\n  then\n    if [ \"$EMOJI\" != \":headphones:\" ];\n    then\n      echo \"Slack status is $EMOJI, not :headphones: or empty, waiting for $DELAY seconds…\"\n      sleep $DELAY\n      continue\n    fi\n  fi\n\n  RUNNING=$(pgrep -lf Spotify)\n  # Bail if Spotify is not running to prevent `osascript` from launching it\n  # Do not bail if Slack is not running as it might be running on the phone\n  if [ -z \"$RUNNING\" ];\n  then\n    echo \"Spotify is off, waiting for $DELAY seconds…\"\n    sleep $DELAY\n    continue\n  fi\n\n  # See `/Applications/Spotify.app/Contents/Resources/Spotify.sdef`\n  STATE=$(osascript -e 'tell application \"Spotify\" to player state')\n  ARTIST=$(osascript -e 'tell application \"Spotify\" to artist of current track')\n  SONG=$(osascript -e 'tell application \"Spotify\" to name of current track')\n\n  # Bail if Spotify is not in playing state (paused, stopped) but is running\n  if [ \"$STATE\" != \"playing\" ];\n  then\n    echo \"Spotify is not playing anything, waiting for $DELAY seconds…\"\n    sleep $DELAY\n    continue\n  fi\n\n  # Schedule status expiration for 5 minutes from now to clear if not replaced\n  STAMP=$(date -v\"+1M\" +%s)\n  REQUEST_JSON=$(echo '{}' | jq --arg SONG \"$SONG\" --arg ARTIST \"$ARTIST\" --arg STAMP $STAMP '.profile.status_text=$ARTIST+\" - \"+$SONG | .profile.status_emoji=\":headphones:\" | .profile.status_expiration=($STAMP|tonumber)')\n\n  # See https://api.slack.com/docs/presence-and-status#custom_status\n  RESPONSE_JSON=$(curl -X POST --data \"$REQUEST_JSON\" -H \"Authorization: Bearer $TOKEN\" -H \"Content-Type: application/json; charset=utf-8\" --no-progress-meter https://slack.com/api/users.profile.set | jq 'del(.profile)')\n\n  echo \"$(date -Iseconds) $(echo \"$REQUEST_JSON\" | jq '.profile.status_text') $(echo \"$RESPONSE_JSON\" | jq '.ok')\"\n  \n  # Wait for a minute in between the status updates\n  sleep $DELAY\ndone\n```\n\nTo use, copy-paste it to a file named `spotify-slack-status.sh` and\nrun `chmod +x spotify-slack-status.sh` and then `./spotify-slack-status.sh`.\n\nThe script will set the status to expire in a minute so that if either the script\nor Spotify quit abruptly, the status will be cleared and won't linger around.\n\nNote that sometimes due to sheer coincidence the script might pick up new song\nname but old artist name.\nIf this happens, it will be fixed in the next loop run in 10 seconds, so it is no\nbiggie.\n\nThe script that gave me the push to attempt my own version of this is here:\nhttps://gist.github.com/jgamblin/9701ed50398d138c65ead316b5d11b26\n\nIt helped me figure out how to use `osascript` to talk to Spotify, but it is\nusing the legacy token type which is no longer supported and I replaced it with\na Slack app and it also uses a Slack API endpoint which no longer exists and I\nreplaced it with a correct one based on the current Slack API documentation.\n\n## Login Item\n\nTo make this script run on macOS startup, do the following:\n\n- Create a file named `spotify-slack-status.command` alongside the main script\n- Make the file executable using `chmod +x spotify-slack-status.command`\n- Put the following content into the file:\n  ```sh\n  screen -d -m ./Desktop/…/spotify-slack-status.sh -S spotify-slack-status\n  exit\n  ```\n- Go to Apple \u003e System Settings \u003e General \u003e Login Items \u003e +\n- Find the `spotify-slack-status.command` file and add it as a login item\n- Go to Apple \u003e Log Out and then log back in to a new macOS user session\n\nYou will be greeter with a Terminal window that says that the process exited.\nThis window will appear after each log in into macOS and is safe to close.\nThe Spotify Slack status updated script is now running in the background.\nYou can verify this by running `screen -ls` or this command:\n`ps x | grep spotify-slack-status | grep SCREEN`\n\nTo monitor the script's output, run `screen -r $PID` where `$PID` is the number\nshown when running the previous command.\n\nTo exit the output monitoring without killing the script, press Ctrl+a+d.\nTo kill the script, press Ctrl+C instead.\n\n## To-Do\n\n### Skip the status update if it would have resulted in the same status text\n\nSlack seems to animate the status updates in the people roster and the status\ndropdown so potentially it would pulse every 10 seconds even when there is a need\nto update the status every 3-5 minutes depending on the songs.\n\nI will introduce a new check to bail if the existing status and new status have\nthe same text.\n\nAlthought I need to think about how this will interact with the short status\nexpiration.\nMaybe I can fetch the song length from Spotify and set the status expiration to\nthat but that will re-introduce the problem with mismatched artist and song in\ncase of that race condition.\n\n### Consider uploading the album art for the album as a custom status emoji\n\nTo get the album image, use:\n`osascript -e 'tell application \"Spotify\" to artwork url of current track'`\n\nHere's how you add emoji by hand:\nhttps://slack.com/help/articles/206870177-Add-custom-emoji-and-aliases-to-your-workspace\n\nHere's an API that can be used to do that programatically:\nhttps://api.slack.com/methods/admin.emoji.add\n\nI could upload a custom emoji for each album and use it as a status emoji.\nI would need to adjust the check to check for a prefix/suffix not for the\n`:headphones:` emoji.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftomashubelbauer%2Fspotify-slack-status","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftomashubelbauer%2Fspotify-slack-status","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftomashubelbauer%2Fspotify-slack-status/lists"}