- 
      
- 
        Save olebedev/298b456897d04ec85b683b88f11ff820 to your computer and use it in GitHub Desktop. 
Revisions
- 
        olebedev revised this gist Apr 19, 2020 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewingThis 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 charactersOriginal file line number Diff line number Diff line change @@ -11,8 +11,8 @@ <key>StartInterval</key> <integer>60</integer> <!-- <key>StandardOutPath</key> <string>/PATH/TO/slackspotify-output.log</string> <key>StandardErrorPath</key> <string>/PATH/TO//slackspotify-errors.log</string> --> </dict> </plist> 
- 
        olebedev revised this gist Apr 19, 2020 . 4 changed files with 26 additions and 11 deletions.There are no files selected for viewingThis 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1 @@ .apikey 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 charactersOriginal file line number Diff line number Diff line change @@ -10,5 +10,9 @@ <true/> <key>StartInterval</key> <integer>60</integer> <!-- <key>StandardOutPath</key> <string>/Users/olebedev/slackspotify-output.txt</string> <key>StandardErrorPath</key> <string>/Users/olebedev/slackspotify-errors.txt</string> --> </dict> </plist> 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 charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,7 @@ { "defined": { "text": "", "emoji": ":finn:" }, "playing_emoji": ":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 charactersOriginal file line number Diff line number Diff line change @@ -2,9 +2,11 @@ set -eu # Get your api key here https://api.slack.com/custom-integrations/legacy-tokens and puth it into .apikey file. SCRIPT_DIR="$(dirname $0)" APIKEY=$(cat "${SCRIPT_DIR}"/.apikey) DATA="${SCRIPT_DIR}"/data.json JQ_BIN=/usr/local/bin/jq function post_status() { @@ -13,7 +15,7 @@ function post_status() { -H "Content-type: application/json; charset=utf-8" \ -H "Authorization: Bearer ${APIKEY}" \ -d "${payload}" \ https://slack.com/api/users.profile.set >/dev/null } function current_slack_status() { @@ -35,21 +37,29 @@ function maybe_save_current_status() { local text="$(echo "${status}" | ${JQ_BIN} -r '.text')" if [[ "${playing}" != "${emoji}" ]]; then local new=$(${JQ_BIN} -n -r --arg text "${text}" --arg emoji "${emoji}" --arg playing "${playing}" '.defined.text = $text | .defined.emoji = $emoji | .playing_emoji = $playing') echo "${new}" > "${DATA}" fi } is_spotify_running() { ps aux | grep -v grep | grep -v slackspotify | grep -c spotify >/dev/null } function main() { date maybe_save_current_status if ! is_spotify_running; then echo "Spotify is not running on this machine." exit 0 else echo "Spotify is "$(echo_state)"." fi if [[ "$(echo_state)" != "playing" ]]; then post_status "$(${JQ_BIN} -r '.defined.emoji //empty' ${DATA})" "$(${JQ_BIN} -r '.defined.text //empty' ${DATA})" else post_status "$(${JQ_BIN} -r '.playing_emoji //empty' ${DATA})" "$(echo_song)" fi } 
- 
        olebedev revised this gist Oct 29, 2019 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewingThis 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 charactersOriginal file line number Diff line number Diff line change @@ -17,4 +17,6 @@ $ launchctl load ~/Library/LaunchAgents/com.user.slack-spotify.plist 4. Start it by either logging out and back in or running ``` $ launchctl start com.user.slack-spotify ``` 6. (Optional) Modify your 'playing' emoji in `./data.json`. 
- 
        olebedev revised this gist Aug 2, 2019 . 1 changed file with 9 additions and 8 deletions.There are no files selected for viewingThis 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 charactersOriginal file line number Diff line number Diff line change @@ -5,9 +5,10 @@ set -eu APIKEY="From Here https://api.slack.com/custom-integrations/legacy-tokens" DATA="$(dirname $0)"/data.json JQ_BIN=/usr/local/bin/jq function post_status() { local payload="$(${JQ_BIN} -n -r --arg emoji "${1}" --arg text "${2}" '{"profile":{"status_text":$text,"status_emoji":$emoji}}')" curl -s \ -H "Content-type: application/json; charset=utf-8" \ -H "Authorization: Bearer ${APIKEY}" \ @@ -16,7 +17,7 @@ function post_status() { } function current_slack_status() { curl -s "https://slack.com/api/users.profile.get?token=${APIKEY}" | ${JQ_BIN} -r '{ text: .profile.status_text, emoji: .profile.status_emoji }' } function echo_state() { @@ -28,13 +29,13 @@ function echo_song() { } function maybe_save_current_status() { local playing="$(${JQ_BIN} -r '.playing_emoji' ${DATA})" local status=$(current_slack_status) local emoji="$(echo "${status}" | ${JQ_BIN} -r '.emoji')" local text="$(echo "${status}" | ${JQ_BIN} -r '.text')" if [[ "${playing}" != "${emoji}" ]]; then local new=$(${JQ_BIN} -r --arg text "${text}" --arg emoji "${emoji}" '.defined.text = $text | .defined.emoji = $emoji' "${DATA}") echo new data: "${new}" echo "${new}" > "${DATA}" fi @@ -46,9 +47,9 @@ function main() { maybe_save_current_status if [[ "$(echo_state)" != "playing" ]]; then post_status "$(${JQ_BIN} -r '.defined.emoji' ${DATA})" "$(${JQ_BIN} -r '.defined.text' ${DATA})" else post_status "$(${JQ_BIN} -r '.playing_emoji' ${DATA})" "$(echo_song)" fi } 
- 
        olebedev revised this gist Aug 2, 2019 . 3 changed files with 62 additions and 21 deletions.There are no files selected for viewingThis 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 charactersOriginal file line number Diff line number Diff line change @@ -1,9 +1,20 @@ # Usage 0. Get API key [here](https://api.slack.com/custom-integrations/legacy-tokens) and put it into `./slackspotify.sh` as an `APIKEY` value. 1. Copy the `com.user.slack-spotify.plist` file into `~/Library/LaunchAgents/com.user.slack-spotify.plist` ``` $ cp com.user.slack-spotify.plist ~/Library/LaunchAgents/com.user.slack-spotify.plist ``` 2. Modify `~/Library/LaunchAgents/com.user.slack-spotify.plist` accordinally -- set path to your `./slackspotify.sh` script. 3. Register this daemon with launchd by running ``` $ launchctl load ~/Library/LaunchAgents/com.user.slack-spotify.plist ``` 4. Start it by either logging out and back in or running ``` $ launchctl start com.user.slack-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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,7 @@ { "defined": { "emoji": "", "text": "" }, "playing_emoji": ":headphones:" } 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 charactersOriginal file line number Diff line number Diff line change @@ -1,31 +1,54 @@ #!/usr//bin/env bash set -eu APIKEY="From Here https://api.slack.com/custom-integrations/legacy-tokens" DATA="$(dirname $0)"/data.json function post_status() { local payload="$(jq -n -r --arg emoji "${1}" --arg text "${2}" '{"profile":{"status_text":$text,"status_emoji":$emoji}}')" curl -s \ -H "Content-type: application/json; charset=utf-8" \ -H "Authorization: Bearer ${APIKEY}" \ -d "${payload}" \ https://slack.com/api/users.profile.set > /dev/null } function current_slack_status() { curl -s "https://slack.com/api/users.profile.get?token=${APIKEY}" | jq -r '{ text: .profile.status_text, emoji: .profile.status_emoji }' } function echo_state() { osascript -e 'tell application "Spotify" to player state' } function echo_song() { osascript -e 'tell application "Spotify" to artist of current track & " - " & name of current track' } function maybe_save_current_status() { local playing="$(jq -r '.playing_emoji' ${DATA})" local status=$(current_slack_status) local emoji="$(echo "${status}" | jq -r '.emoji')" local text="$(echo "${status}" | jq -r '.text')" if [[ "${playing}" != "${emoji}" ]]; then local new=$(jq -r --arg text "${text}" --arg emoji "${emoji}" '.defined.text = $text | .defined.emoji = $emoji' "${DATA}") echo new data: "${new}" echo "${new}" > "${DATA}" fi } function main() { date echo "Spotify is "$(echo_state)". Current song is: '"$(echo_song)"'." maybe_save_current_status if [[ "$(echo_state)" != "playing" ]]; then post_status "$(jq -r '.defined.emoji' ${DATA})" "$(jq -r '.defined.text' ${DATA})" else post_status "$(jq -r '.playing_emoji' ${DATA})" "$(echo_song)" fi } 
- 
        olebedev revised this gist May 29, 2019 . 3 changed files with 53 additions and 8 deletions.There are no files selected for viewingThis 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,9 @@ # Usage 1. Link the `com.user.slack-spotify.plist` file into `~/Library/LaunchAgents/com.user.slack-spotify.plist` 2. Register this daemon with launchd by running launchctl load ~/Library/LaunchAgents/com.user.slack-spotify.plist 3. Start it by either logging out and back in or running launchctl start com.user.slack-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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,14 @@ <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>Label</key> <string>com.user.slack-spotify</string> <key>ProgramArguments</key> <array><string>/PATH/TO/SCRIPT.sh</string></array> <key>RunAtLoad</key> <true/> <key>StartInterval</key> <integer>60</integer> </dict> </plist> 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 charactersOriginal file line number Diff line number Diff line change @@ -1,10 +1,32 @@ #!/bin/bash APIKEY="From Here https://api.slack.com/custom-integrations/legacy-tokens" EMOJI=$(echo :headphones: | perl -MURI::Escape -ne 'chomp;print uri_escape($_),"\n"') function reset() { echo 'Resetting status' curl -s -d "payload=$json" "https://slack.com/api/users.profile.set?token="$APIKEY"&profile=%7B%0A%20%20%20%20%22status_text%22%3A%20%22%22%2C%0A%20%20%20%20%22status_emoji%22%3A%20%22"$EMOJI"%22%0A%7D" > /dev/null } function set_status() { SONG=$(osascript -e 'tell application "Spotify" to artist of current track & " - " & name 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%0A%20%20%20%20%22status_text%22%3A%20%22"$URLSONG"%22%2C%0A%20%20%20%20%22status_emoji%22%3A%20%22"$EMOJI"%22%0A%7D" > /dev/null } function main() { state=$(osascript -e 'tell application "Spotify" to player state') date echo "Spotify: "$state if [[ "$state" != "playing" ]]; then reset else set_status fi } main 
- 
        jgamblin created this gist Apr 19, 2017 .There are no files selected for viewingThis 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,10 @@ #!/bin/bash APIKEY="From Here https://api.slack.com/custom-integrations/legacy-tokens" SONG=$(osascript -e 'tell application "Spotify" to name of current track as string') URLSONG=$(echo "$SONG" | perl -MURI::Escape -ne 'chomp;print uri_escape($_),"\n"') while true do curl -s -d "payload=$json" "https://slack.com/api/users.profile.set?token="$APIKEY"&profile=%7B%22status_text%22%3A%22"$URLSONG"%22%2C%22status_emoji%22%3A%22%3Amusical_note%3A%22%7D" > /dev/null sleep 60 done