https://github.com/sindresorhus/node-dark-mode
Control the macOS dark mode
https://github.com/sindresorhus/node-dark-mode
dark-mode javascript macos nodejs
Last synced: 6 months ago
JSON representation
Control the macOS dark mode
- Host: GitHub
- URL: https://github.com/sindresorhus/node-dark-mode
- Owner: sindresorhus
- License: mit
- Created: 2014-10-17T23:58:16.000Z (over 11 years ago)
- Default Branch: main
- Last Pushed: 2025-09-09T12:31:36.000Z (8 months ago)
- Last Synced: 2025-10-11T00:22:31.083Z (7 months ago)
- Topics: dark-mode, javascript, macos, nodejs
- Language: JavaScript
- Homepage:
- Size: 23.4 KB
- Stars: 117
- Watchers: 5
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
# node-dark-mode
> Control the macOS dark mode
*Requires macOS 10.10 or later.*

## Install
```sh
npm install dark-mode
```
## Usage
```js
import darkMode from 'dark-mode';
await darkMode.enable();
console.log('Enabled dark mode');
await darkMode.toggle();
console.log('Toggled between dark and light mode');
```
## API
### darkMode
All the methods return a `Promise`, except for `.watch()`.
#### .enable()
#### .disable()
#### .toggle(force?)
##### force
Type: `boolean`
Force a specific mode. `true` for dark and `false` for light.
#### .isEnabled()
Returns a `Promise` of whether you're in dark mode.
#### .watch(callback)
Watch for dark mode changes.
##### callback
Type: `(isDarkMode: boolean) => void`
Function to call when dark mode changes.
Returns a watcher object with a `stop` method.
```js
import darkMode from 'dark-mode';
const watcher = darkMode.watch(isDark => {
console.log('Dark mode is now:', isDark ? 'enabled' : 'disabled');
});
// Later, stop watching
watcher.stop();
```
## Related
- [dark-mode-cli](https://github.com/sindresorhus/dark-mode-cli) - CLI for this module
- [alfred-dark-mode](https://github.com/sindresorhus/alfred-dark-mode) - Alfred workflow