LionyxML/auto-dark-emacs
{ "createdAt": "2019-07-17T00:28:47Z", "defaultBranch": "master", "description": "Auto-Dark-Emacs is an auto changer between 2 themes, dark/light, following MacOS, Linux or Windows Dark Mode settings", "fullName": "LionyxML/auto-dark-emacs", "homepage": "", "language": "Emacs Lisp", "name": "auto-dark-emacs", "pushedAt": "2025-10-06T04:03:45Z", "stargazersCount": 221, "topics": [ "automation", "emacs", "theme" ], "updatedAt": "2025-11-21T23:14:05Z", "url": "https://github.com/LionyxML/auto-dark-emacs"}Auto-Dark for Emacs
Section titled “Auto-Dark for Emacs”
|
|
|
|
|
Dev:
|
Prod:
|
Want Emacs to automatically follow your system’s dark mode on macOS, Linux, Windows, or even Android?
Installation · Settings · Screenshots
This package, auto-dark-mode, introduces a minor mode in Emacs that
enables automatic switching between two user-defined (customizable)
themes. This transition occurs seamlessly in response to Dark Mode
being enabled or disabled across MacOS, Linux, Windows, and Android
platforms.
For now it supports Linux through dbus and Android via Termux.
Installation
Section titled “Installation”Regular Emacs
Section titled “Regular Emacs”Install it from MELPA and add to your
.emacs or init.el file:
(require 'auto-dark)(auto-dark-mode)Or simply copy the auto-dark.el file to
~/.emacs.d/auto-dark/auto-dark.el (or clone this repository there),
and then add the following to your .emacs:
(add-to-list 'load-path "~/.emacs.d/auto-dark/")(require 'auto-dark)(auto-dark-mode)Or use use-package to install:
(use-package auto-dark :init (auto-dark-mode))Spacemacs
Section titled “Spacemacs”If you use Spacemacs, add (auto-dark) to the
dotspacemacs-additional-packages list and add the following to
dotspacemacs/user-config:
(use-package auto-dark :init (spacemacs/defer-until-after-user-config #'auto-dark-mode) :defer t)This ensures that auto-dark-mode is activated only after spacemacs’s
built-in theme loading logic.
Doom Emacs
Section titled “Doom Emacs”If you use Doom Emacs, load the package in your packages.el:
;; In your packages.el(package! auto-dark)And put the following snippet in your config.el:
(use-package! auto-dark :defer t :init ;; Configure themes (setq! auto-dark-themes '((doom-solarized-dark) (doom-solarized-light))) ;; Disable doom's theme loading mechanism (just to make sure) (setq! doom-theme nil) ;; Declare that all themes are safe to load. ;; Be aware that setting this variable may have security implications if you ;; get tricked into loading untrusted themes (via auto-dark-mode or manually). ;; See the documentation of custom-safe-themes for details. (setq! custom-safe-themes t) ;; Enable auto-dark-mode at the right point in time. ;; This is inspired by doom-ui.el. Using server-after-make-frame-hook avoids ;; issues with an early start of the emacs daemon using systemd, which causes ;; problems with the DBus connection that auto-dark mode relies upon. (defun my-auto-dark-init-h () (auto-dark-mode) (remove-hook 'server-after-make-frame-hook #'my-auto-dark-init-h) (remove-hook 'after-init-hook #'my-auto-dark-init-h)) (let ((hook (if (daemonp) 'server-after-make-frame-hook 'after-init-hook))) ;; Depth -95 puts this before doom-init-theme-h, which sounds like a good ;; idea, if only for performance reasons. (add-hook hook #'my-auto-dark-init-h -95)))Notes for MacOS users
Section titled “Notes for MacOS users”From the box, this package takes advantage of some built-in functionality found on the formulaes Emacs Plus and Emacs Mac to make detecting switches faster.
If you compiled Emacs yourself or used any other pre-compiled binary,
it is essential to explicitly instruct auto-dark you want to use
Osascript.
You can do this by adding to your configuration:
(setq auto-dark-allow-osascript t)Doing so will probably make MacOS prompt you for security permissions. If by any chance it does not prompt you, you can check permissions on MacOS by going to:
Settings -> Privacy & Security -> Emacs -> System EventsAlso notice if you run emacs from the terminal, Osascript is the only method that
will work.
Notes for Emacs Daemon / Server Mode Users
Section titled “Notes for Emacs Daemon / Server Mode Users”If you start Emacs as a daemon (emacs --daemon), auto-dark-mode may not
correctly detect the system theme when the first GUI frame is created. This is
because the theme detection runs before the first frame is available.
To fix this, you can add a hook to run auto-dark-mode after the first frame
is created:
(defun my/server-auto-dark (frame) (with-selected-frame frame (when (display-graphic-p) (auto-dark-mode 1) ;; Remove hook so it only runs once (remove-hook 'after-make-frame-functions #'my/server-auto-dark))))
(use-package auto-dark :config (setq auto-dark-themes '((modus-operandi) (modus-vivendi))) (add-hook 'after-make-frame-functions #'my/server-auto-dark))Also, take a look at #32 and #71 issues.
Settings
Section titled “Settings”All provided options, including The light/dark themes can be
customized using the Emacs customization system. M-x customize-group auto-dark RET.
You can also take advantage of the hooks auto-dark-dark-mode-hook
and auto-dark-light-mode-hook to make it even further
customizable. Take a look at this article on how to Integrate
Catppuccin with
Auto-Dark.
Following, a complete configuration with all settings set to its defaults:
(use-package auto-dark :ensure t :custom (auto-dark-themes '((wombat) (leuven))) (auto-dark-polling-interval-seconds 5) (auto-dark-allow-osascript nil) (auto-dark-allow-powershell nil) ;; (auto-dark-detection-method nil) ;; dangerous to be set manually :hook (auto-dark-dark-mode . (lambda () ;; something to execute when dark mode is detected )) (auto-dark-light-mode . (lambda () ;; something to execute when light mode is detected )) :init (auto-dark-mode))A short description of each setting:
auto-dark-themes
Section titled “auto-dark-themes”A list containing two elements. The first is the list of themes to enable when dark-mode is active and the second is the list of themes to enable when dark-mode is inactive.
Possible values for each sublist are themes installed on your system found by
customize-themes or nil to use Emacs with no themes (default appearance).
If this variable is nil, then the set of themes from custom-enabled-themes
will be used for both dark and light mode. These themes must support
frame-background-mode, or else there will be no visible change.
NB: When adding themes to this list, switching between light and dark, or
initializing Emacs, you may see a prompt like “Loading a theme can run Lisp
code. Really load?” If you answer “yes” and allow Emacs to treat the theme as
safe in future sessions, you should only see this prompt once per theme. To
disable the prompt completely, you can set custom-safe-themes to t before
setting auto-dark-themes.
auto-dark-polling-interval-seconds
Section titled “auto-dark-polling-interval-seconds”The number of seconds between which to poll for dark mode state. Emacs must be restarted for this value to take effect.
This is here for when there’s no emacs-plus (MacOS), or emacs-mac (MacOS) or a system with dbus or capable of sending events is found, a timed polling is called to check the current system status.
auto-dark-allow-osascript
Section titled “auto-dark-allow-osascript”Whether to allow function auto-dark-mode to shell out to osascript:
to check dark-mode state, if ns-do-applescript or mac-do-applescript.
This is only useful for MacOS, please check the section Notes for MacOS users above.
auto-dark-allow-powershell
Section titled “auto-dark-allow-powershell”Whether to allow function auto-dark-mode to shell out to powershell:
to check dark-mode state.
This is only useful for Windows. If not set, it will use the built-in Emacs
Windows Registry functions.
auto-dark-dark-mode-hook
Section titled “auto-dark-dark-mode-hook”List of hooks to run after dark mode is loaded.
You can use this hook to take leverage of auto-dark detection system and
issue more elisp code when some state is detected. You can even use only the
hooks by setting the themes to nil.
auto-dark-light-mode-hook
Section titled “auto-dark-light-mode-hook”“List of hooks to run after light mode is loaded.”
You can use this hook to take leverage of auto-dark detection system and
issue more elisp code when some state is detected. You can even use only the
hooks by setting the themes to nil.
auto-dark-detection-method
Section titled “auto-dark-detection-method”The method auto-dark should use to detect the system theme.
Defaults to nil and will be populated through feature detection if left as such. Only set this variable if you know what you’re doing!
Screenshots
Section titled “Screenshots”This package in action:
- macOS (emacs-plus formulae)
![auto-dark-emacs in action - macos - emacs-plus]!(images/demo_emacs_plus.gif)
- macOS (emacs-mac formulae)
![auto-dark-emacs in action - macos - emacs-mac]!(images/demo_emacs_mac.gif)
- Linux (Gnome DE)
![auto-dark-emacs in action - linux gnome]!(images/demo_gnome.gif)