Deschant Kounou
Deschant Kounou

Reputation: 53

Can I change vscode color theme programmatically?

Does the vscode api allow us to change the currently set color theme ?

Upvotes: 1

Views: 733

Answers (1)

Mark
Mark

Reputation: 181140

Yes, this works:

let currentTheme = await vscode.workspace.getConfiguration().get("workbench.colorTheme");

await vscode.workspace.getConfiguration().update("workbench.colorTheme", "Red");

let newTheme = await vscode.workspace.getConfiguration().get("workbench.colorTheme");

It seems a little funky on testing in the Extension Development Host but even though currentTheme may beundefined when the current theme is not set by workbench.colorTheme (as a default themes don't seem to necessarily be) the update() still does work.

vscode.window.activeColorTheme does not get the active theme name, only whether it is Dark/Light/HighContrast and is not settable - but you can see what the user's current preference is with respect to dark/light/high contrast at least.

Upvotes: 2

Related Questions