Skip to content

apply-obsidian-theme

Switches the driven Obsidian to its dark or light theme, and makes the switch survive a config reload.

app.changeTheme only sets the theme in the in-memory config and SCHEDULES the save, a second later (requestSaveConfig is debounced). Until that save lands, any file-watcher event on .obsidian/app.json or .obsidian/appearance.json makes Obsidian run vault.reloadConfig, which re-reads both files and deletes every in-memory key the disk does not have — theme included. The body then falls back to the light theme, and a capture suite that set the dark theme shoots every frame light, silently writing over the frames it has committed. Read from the 1.14.2 app.js, and reproduced in a plugin’s capture suite: one external rewrite of app.json straight after changeTheme turned all five of its desktop frames light.

applyObsidianTheme saves the config at once, so a reload finds the theme on disk and has nothing to drop, and waits until the body carries the theme’s class and appearance.json carries its name. It also records the theme it applied, so captureObsidianScreenshot can refuse a frame the theme has left since.

Interface Description
ApplyObsidianThemeParams Parameters for applyObsidianTheme.
AssertObsidianThemeUnchangedParams Parameters for assertObsidianThemeUnchanged.
Function Description
applyObsidianTheme Switches Obsidian to its dark or light theme, saves the config at once, and waits until the theme is both on screen and on disk. Use it instead of app.changeTheme in a capture suite: see the module comment for the reload that silently undoes a bare changeTheme. The theme is recorded, and captureObsidianScreenshot then refuses any frame whose body is no longer in it, so a theme lost after this call fails the capture by name instead of rewriting a committed frame.
assertObsidianThemeUnchanged Throws when the body has left the theme applyObsidianTheme applied. Nothing is checked when no theme was applied through it, since there is then no expectation to hold the frame to.
Type Description
ObsidianTheme One of Obsidian’s two built-in base themes.