Step 1: OAuth
これの「準備2」まで行う
(Slackワークスペースにアプリのインストールを行う必要がある)
Step 2: こちらのコードを持ってきて動かす
APIKEY
に Step 1 で取ってきたアクセストークンをいれて、動かす
https://gist.github.com/jgamblin/9701ed50398d138c65ead316b5d11b26#gistcomment-2792595
#!/bin/bash
# from: https://gist.github.com/jgamblin/9701ed50398d138c65ead316b5d11b26#gistcomment-2792595
# by laurentfite@github
# Get it from here : https://api.slack.com/custom-integrations/legacy-tokens
APIKEY="XXXXXXXXXX"
trap onexit INT
function reset() {
echo 'Resetting status'
TEXT='Winter%20is%20coming%20(at%20last)'
EMOJI='snowflake'
curl -s -d "payload=$json" "https://slack.com/api/users.profile.set?token="$APIKEY"&profile=%7B%22status_text%22%3A%22"$TEXT"%22%2C%22status_emoji%22%3A%22%3A"$EMOJI"%3A%22%7D" > /dev/null
}
function onexit() {
echo 'Exiting'
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 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%22status_text%22%3A%22"$URLSONG"%22%2C%22status_emoji%22%3A%22%3Aheadphones%3A%22%7D" > /dev/null
fi
sleep 60
done
さらに以下のように launchd に設定すれば、自動起動される
https://gist.github.com/jgamblin/9701ed50398d138c65ead316b5d11b26#gistcomment-2775093