aboutsummaryrefslogtreecommitdiff
path: root/users/ryan/modules/sketchybar/bar-config/plugins/spotify.sh
blob: 8d91297f6eff67420bafcc96000aece652daffec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#!/usr/bin/env bash
# custom/spotify -> now playing, driven by the native media_change event.
source "$HOME/.config/sketchybar/icons.sh"

# Waybar on-click: playerctl play-pause
if [ "$1" = "toggle" ]; then
  osascript -e 'tell application "Spotify" to playpause' 2>/dev/null
  exit 0
fi

STATE="$(printf '%s' "$INFO"  | sed -nE 's/.*"state":"([^"]*)".*/\1/p')"
TITLE="$(printf '%s' "$INFO"  | sed -nE 's/.*"title":"([^"]*)".*/\1/p')"
ARTIST="$(printf '%s' "$INFO" | sed -nE 's/.*"artist":"([^"]*)".*/\1/p')"

# exec-if check-for-music -> only draw while something is playing
if [ "$STATE" = "playing" ] && [ -n "$TITLE" ]; then
  sketchybar --set "$NAME" drawing=on label="$TITLE - $ARTIST"
else
  sketchybar --set "$NAME" drawing=off
fi