Quantcast
Channel: Bashタグが付けられた新着記事 - Qiita
Viewing all articles
Browse latest Browse all 2914

Spofity視聴中の曲をSlackステータスに投稿 (macOS専用)

$
0
0

Step 1: OAuth

これの「準備2」まで行う
(Slackワークスペースにアプリのインストールを行う必要がある)

https://qiita.com/keiya/items/b72f89e3a8a75121c02e

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-tokensAPIKEY="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: "$stateif[["$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


Viewing all articles
Browse latest Browse all 2914

Trending Articles