Last active
September 22, 2025 19:15
-
-
Save m99coder/98b11e9e1edca172156fdf7f6de83764 to your computer and use it in GitHub Desktop.
Obsidian Profile Switcher QuickAdd Custom Script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module.exports = async (params) => { | |
| const { app, quickAddApi } = params; | |
| // profile configurations | |
| const appearance = { | |
| markdown: { | |
| cssTheme: "Material Gruvbox", | |
| theme: "obsidian", | |
| textFontFamily: "FiraCode Nerd Font", | |
| baseFontSize: 14, | |
| }, | |
| text: { | |
| cssTheme: "Typomagical", | |
| theme: "moonstone", | |
| textFontFamily: "Alegreya", | |
| baseFontSize: 18, | |
| }, | |
| }; | |
| const communityPlugins = { | |
| markdown: { | |
| typewriterModeEnabled: false, | |
| }, | |
| text: { | |
| typewriterModeEnabled: true, | |
| }, | |
| }; | |
| // read profile selection | |
| const profile = await quickAddApi.suggester( | |
| ["Markdown", "Text"], | |
| ["markdown", "text"] | |
| ); | |
| const appearanceConfig = await app.vault.adapter.read( | |
| ".obsidian/appearance.json" | |
| ); | |
| let appearanceSettings = JSON.parse(appearanceConfig); | |
| // update appearance | |
| appearanceSettings = { | |
| ...appearanceSettings, | |
| ...appearance[profile], | |
| }; | |
| await app.vault.adapter.write( | |
| ".obsidian/appearance.json", | |
| JSON.stringify(appearanceSettings, null, 2) | |
| ); | |
| // toggle typewriter mode plugin | |
| const pluginPath = ".obsidian/plugins/typewriter-mode/data.json"; | |
| const pluginConfigRaw = await app.vault.adapter.read(pluginPath); | |
| const pluginConfig = JSON.parse(pluginConfigRaw); | |
| pluginConfig.isPluginActivated = | |
| communityPlugins[profile].typewriterModeEnabled; | |
| await app.vault.adapter.write( | |
| pluginPath, | |
| JSON.stringify(pluginConfig, null, 2) | |
| ); | |
| // reload plugin | |
| const pluginId = "typewriter-mode"; | |
| const pluginInstance = app.plugins.plugins[pluginId]; | |
| if (pluginInstance) { | |
| await app.plugins.disablePlugin(pluginId); | |
| await app.plugins.enablePlugin(pluginId); | |
| } | |
| // manually set theme | |
| app.customCss.setTheme( | |
| profile === "markdown" ? "Material Gruvbox" : "Typomagical" | |
| ); | |
| // rebuild view | |
| await app.workspace.activeLeaf.rebuildView(); | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment