LoginSignup
6

More than 5 years have passed since last update.

Spotifyで再生中の曲をtmuxのステータスバーに表示する

Posted at

はじめに

macOS版のSpotifyアプリがAppleScript APIを持っていることを知ったので、試しにtmuxのステータスバーに再生中のトラック情報を表示するようにしてみました。

試した環境

  • macOS Sierra 10.12.6
  • AppleScript 2.5
  • Spotify 1.0.63.617
  • tmux 2.5

手順

  • 任意のパスに以下のスクリプトファイルを配置します。今回は ~/bin/get-currently-playing-track-on-spotify としました。実行権限もつけておいてください。
~/bin/get-currently-playing-track-on-spotify
#!/usr/bin/osascript

if application "Spotify" is running
  tell application "Spotify"
    if (player state as string) is "playing" then
        set nowPlaying to "♫ "
    else
        set nowPlaying to ""
    end if
    set currentArtist to artist of current track as string
    set currentTrack to name of current track as string
    return nowPlaying & currentArtist & " - " & currentTrack
  end tell
else
  "Spotify is not running."
end if
  • .tmux.confのstatus-rightに追加します。
~/tmux.conf(抜粋)
set -g status-right ' #(~/bin/get-currently-playing-track-on-spotify) ...'

※参考までに私のtmux.confです。
osx-provisioner/.tmux.conf at master · j-un/osx-provisioner

  • tmuxをリロードします。

結果

  • Spotifyで曲を再生すると、ステータスバーにトラック情報が表示されます。


  • 再生を停止すると♫が消える滋味あふれる演出。


  • Spotifyアプリが起動していない時。いらないかな。

補足と雑記

  • 詳細なリファレンスは、スクリプトエディタで以下の方法で参照できます。
    スクリプトエディタ - ファイル - 用語説明を開く - Spotify

  • このままだと曲名が長い時にステータスバーが見切れちゃうので、ある程度の文字数を超えたら切り捨てたりしたほうがいいかもしれません。

参考文献

AppleScript API - Spotify Developer

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6