guidoschmidt / circadian.el

Theme-switching for Emacs based on daytime
https://guidoschmidt.github.io/circadian.el
MIT License
176 stars 8 forks source link

Integration with macOS system theme preference? #22

Open rollcat opened 4 years ago

rollcat commented 4 years ago

I'm looking for a way to synchronise the Emacs theme with light/dark/auto mode on macOS. I understand the current method is completely cross-platform, but it would be great to integrate with specific platforms' capabilities.

guidoschmidt commented 3 years ago

@rollcat I just discovered, that emacs-plus is implementing that feature. Might be worth checking it out. I could imagine to integrate it into circadian.el as well

rollcat commented 3 years ago

Nice find!

In the meantime, I've been able to hack this together:

(setq system-is-mac (equal "darwin" (symbol-name system-type)))

(defun get-appearance-preferences ()
  (if system-is-mac
      (do-applescript "tell application \"System Events\"
  tell appearance preferences
    if (dark mode) then
      return \"dark\"
    else
      return \"light\"
    end if
  end tell
end tell")
    "dark"))
(defun update-theme ()
  (let ((ap (get-appearance-preferences)))
    (cond
        ((equal ap "dark")  (load-theme preferred-dark-theme))
        ((equal ap "light") (load-theme preferred-light-theme))
        (t nil))))

Of course this does not respond to system theme change events; however I've turned off automatic switching, since in the winter I usually want the dark theme enabled earlier in the day than what the system thinks is appropriate (which brings us full circle to the problem that Circadian is addressing...) And instead I have an Automator shortcut which toggles system appearance, followed by running emacsclient -e '(update-theme)'.

I'm probably gonna try emacs-plus though. Thanks :)