Files
opalfiles/.config/waybar/scripts/music.scm
2024-09-09 10:21:40 -07:00

37 lines
1.1 KiB
Scheme
Executable File

#!/usr/bin/env guile3.0
!#
(use-modules (ice-9 popen)
(ice-9 rdelim))
;; Function to get playerctl metadata
(define (get-playerctl-metadata field)
(let* ((command (string-append "playerctl --player=strawberry metadata " field))
(port (open-input-pipe command))
(output (read-line port)))
(close-pipe port)
output))
;; Function to abbreviate a string if it's longer than max-length
(define (abbreviate text max-length)
(if (> (string-length text) max-length)
(string-append (substring text 0 (- max-length 3)) "...")
text))
(define music-note "🎵")
;; Main logic to display artist and title
(let* ((artist (get-playerctl-metadata "artist"))
(title (get-playerctl-metadata "title"))
(display-text
(if (and (string? artist) (string? title))
(abbreviate (string-append artist " - " title) 30)
#f))) ;; Set to #f if artist or title is not available
(if display-text
(begin
(display music-note) ;; Display the music note icon
(display " ")
(display display-text)
(newline))
(display "")))