|
I want to switch the obsidian theme with one click. I feel that the add script should be able to achieve this requirement. Can anyone share a similar script for me to learn and reference? Thanks! |
Replies: 1 comment
|
Coming back to this very late - sorry about that. In case you (or anyone searching) still want it: A QuickAdd macro user script can do this. Create a Macro choice, attach this script as its command, and toggle the command (lightning bolt) on the choice so it's one click away in the command palette or on a hotkey. module.exports = async (params) => {
const { app, quickAddApi } = params;
const customCss = app.customCss;
const themes = ["", ...Object.keys(customCss.themes ?? {})];
const picked = await quickAddApi.suggester(
(theme) => (theme === "" ? "Default" : theme),
themes
);
customCss.setTheme(picked);
};That opens a suggester over your installed themes (plus the default) and applies the pick. If you'd rather have a strict two-theme toggle in a single click, no prompt: module.exports = async (params) => {
const customCss = params.app.customCss;
customCss.setTheme(customCss.theme === "Minimal" ? "Things" : "Minimal");
};(Theme names are exactly as shown in Settings -> Appearance.) One honest caveat: Script basics (params, quickAddApi) are covered here: https://quickadd.obsidian.guide/docs/Advanced/ScriptingGuide Closing as resolved. |
Coming back to this very late - sorry about that. In case you (or anyone searching) still want it:
A QuickAdd macro user script can do this. Create a Macro choice, attach this script as its command, and toggle the command (lightning bolt) on the choice so it's one click away in the command palette or on a hotkey.
That opens a suggester over your installed themes (plus the default) a…