circadian.el icon indicating copy to clipboard operation
circadian.el copied to clipboard

Integration with macOS system theme preference?

Open rollcat opened this issue 5 years ago • 2 comments

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.

rollcat avatar Nov 29 '19 17:11 rollcat

@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

guidoschmidt avatar Jan 09 '21 15:01 guidoschmidt

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 :)

rollcat avatar Jan 09 '21 15:01 rollcat