oh-my-posh/src/segments/spotify_darwin.go

31 lines
832 B
Go
Raw Normal View History

//go:build darwin
2020-11-04 23:56:12 -08:00
2022-01-26 06:54:36 -08:00
package segments
2020-11-04 23:56:12 -08:00
func (s *Spotify) Enabled() bool {
2020-11-04 23:56:12 -08:00
var err error
// Check if running
running := s.runAppleScriptCommand("application \"Spotify\" is running")
if running == "false" || running == "" {
s.Status = stopped
2020-11-04 23:56:12 -08:00
return false
}
2022-01-22 10:46:56 -08:00
s.Status = s.runAppleScriptCommand("tell application \"Spotify\" to player state as string")
2020-11-04 23:56:12 -08:00
if err != nil {
s.Status = stopped
2020-11-04 23:56:12 -08:00
return false
}
2022-01-22 10:46:56 -08:00
if s.Status == stopped {
2020-11-04 23:56:12 -08:00
return false
}
2022-01-22 10:46:56 -08:00
s.Artist = s.runAppleScriptCommand("tell application \"Spotify\" to artist of current track as string")
s.Track = s.runAppleScriptCommand("tell application \"Spotify\" to name of current track as string")
s.resolveIcon()
2020-11-04 23:56:12 -08:00
return true
}
2022-01-26 05:10:18 -08:00
func (s *Spotify) runAppleScriptCommand(command string) string {
val, _ := s.env.RunCommand("osascript", "-e", command)
2020-11-04 23:56:12 -08:00
return val
}