Racket

10th of April, 2022

Previously I've made a repository on Codeberg collecting most of the Star Wars soundtracks. The other day I decided to make Emacs play me a different Star Wars soundtrack depending on the day of the week, and so I made this small Elisp script I called Racket.

It's very simple really, but I'm new to this language so I was still happy when I got it to work.

(defun racket-play-star-wars-music ()
  "Play a different Star Wars soundtrack depending on the day of the week."
  (emms-play-directory-tree
    (let ((day-of-week (substring (current-time-string) 0 3))
          (star-wars-directory ""))
      (when (equal day-of-week "Sun")
        (setq star-wars-directory "01 The Phantom Menace"))
      (when (equal day-of-week "Mon")
        (setq star-wars-directory "02 Attack of the Clones"))
      (when (equal day-of-week "Tue")
        (setq star-wars-directory "03 Revenge of the Sith"))
      (when (equal day-of-week "Wed")
        (setq star-wars-directory "04 A New Hope"))
      (when (equal day-of-week "Thu")
        (setq star-wars-directory "05 The Empire Strikes Back"))
      (when (equal day-of-week "Fri")
        (setq star-wars-directory "06 Return of the Jedi"))
      (when (equal day-of-week "Sat")
        (setq star-wars-directory "The Mandalorian"))
      (string-join (list "~/Music/star-wars-soundtrack/" star-wars-directory)))))

The current-time-string function returns a string with a format like this: Mon Jan 01 00:00:00 1970. The script retrieves the first three letters of the string to get the day of the week, and then compares it to select a folder inside the star-wars-soundtrack repository.

You can see the source code here.