DiNitride / Discord-Music-Status

A Self-Bot program to display your music from Spotify, iTunes, Winamp, and other music players, as your "Playing" status on Discord
72 stars 19 forks source link

macOS Solution for Spotify Sink #27

Open williamtdr opened 6 years ago

williamtdr commented 6 years ago

Hey! Wanted to get this working on my Mac, so I used the following script to generate a file that gets updated from what's playing in Spotify. This doesn't give you nearly the range of service support you get with Snip, but in my case it's all I need. Might be worth a note in the README if people are interested in getting it working on macOS.

neptune:tmp synapses$ cat nowPlaying.osascript 
#!/usr/bin/osascript
#
# now_playing.osascript
#
# Osascript to fetch the meta data of the currently playing
# track in Spotify. This works only on Mac OS X.

tell application "System Events"
  set myList to (name of every process)
end tell
if myList contains "Spotify" then
  tell application "Spotify"
    if player state is stopped then
      set output to "---"
    else
      set trackname to name of current track
      set artistname to artist of current track
      set albumname to album of current track
      if player state is playing then
        set output to trackname & " | " & artistname
      else if player state is paused then
        set output to trackname & " | " & artistname & " | " & "Paused"
      end if
    end if
  end tell
else
  set output to "---"
end if

Thanks for publishing the project! I ended up combining with this with the Spotify Connect web API and running both scripts on my VPS so it always gets updated no matter what I'm playing from (I listen on my phone a lot).

DiNitride commented 6 years ago

Hey! Thanks for this, it's super cool. I've not got a Mac so didn't have anything to test or fiddle with, but I'll shove this in the README, cheers :D

DiNitride commented 6 years ago

Actually, would you be able to edit the README and make a PR for me? Like I said I don't have a mac so I don't really know how to explain this stuff.

williamtdr commented 6 years ago

Will do!

DiNitride commented 6 years ago

Cheers :D