dotfiles/home/apps/sketchybar/plugins/music.sh

24 lines
870 B
Bash
Raw Normal View History

2023-02-24 22:02:18 +01:00
#!/usr/bin/env bash
if pgrep -xq Music; then
2023-02-24 22:02:18 +01:00
STATE=$(osascript -e 'tell application "Music" to player state as string' 2>/dev/null)
TRACK=$(osascript -e 'tell application "Music" to name of current track as string' 2>/dev/null)
ARTIST=$(osascript -e 'tell application "Music" to album artist of current track as string' 2>/dev/null)
2023-02-10 09:13:56 +01:00
# fall back to artist, if album artist is unavailable, or generic
2023-02-24 22:02:18 +01:00
if [[ -z "$ARTIST" ]] || [[ "$ARTIST" = "Various Artists" ]]; then
ARTIST=$(osascript -e 'tell application "Music" to artist of current track as string' 2>/dev/null)
2023-02-10 09:13:56 +01:00
fi
2023-02-24 22:02:18 +01:00
if [[ "$STATE" = "playing" ]]; then
2023-02-10 09:13:56 +01:00
LABEL="$ARTIST - $TRACK"
else
2023-02-24 22:02:18 +01:00
LABEL=""
2023-02-10 09:13:56 +01:00
fi
2023-02-24 22:02:18 +01:00
sketchybar --set "$NAME" label="$LABEL" \
icon.font="Symbols Nerd Font:2048-em:18.0" \
label.font="Victor Mono:Italic:16.0" y_offset="3"
else
2023-02-24 22:02:18 +01:00
sketchybar --set "$NAME" label=""
fi