Use PowerShell to change your VSCode settings
As stated I love the dark theme in Windows. However it might not be the best mode to present sessions in. In my previous blog I stated I use Lumos. And since that allows for updating my Office, I had a look to some of the other tools I use when presenting. Most sessions contain code so I usually use VSCode to present my snippets in. The default mode for VSCode has a black background as well. So for most presentations I switch to a light mode and change the font-size.
Presenting mode
So going in presentation mode always require some manual steps. It therefore made sense to create a small snippet that uses Lumos and to switch. But also can update my VSCode. I ended up with the following two settings to set:
- the font-size
- the color theme
If you require additional settings you can use the same approach. Whatever you think should be in there for your presentation settings. The VSCode settings are saved in the %APPDATA\Code\User\settings.json
folder. It is plain JSON so you can use the ConvertFrom-Json
to get the date you require. Then easily manipulate it using objects. The only thing to take into account is the requirement to pass encoding parameter when saving. If you omit that parameter you might end up with a weird settings file.
$settingsPath = "$env:APPDATA\Code\User\settings.json";
$colorSetting = 'workbench.colorTheme';
$fontSetting = 'editor.fontSize';
$data = $jsondata = Get-Content -Raw -Path $settingsPath -ErrorAction silentlycontinue | ConvertFrom-Json
if($data){
if($data.$colorSetting) {
$data.PSObject.Properties.Remove($colorSetting)
}
else {
$data | Add-Member -Name $colorSetting -Value "Default Light+" -MemberType NoteProperty
}
if($data.$fontSetting) {
$data.PSObject.Properties.Remove($fontSetting)
}
else {
$data | Add-Member -Name $fontSetting -Value "25" -MemberType NoteProperty
}
}
$data | ConvertTo-Json | Out-File $settingsPath -Encoding utf8
When playing around with those settings make sure to make a quick copy of your settings file to prevent the loss of additional config. If you overwrite the file with the wrong input you loose all your settings.
I saved my script to a OneDrive folder that is always present in my machine and made a shortcut to quickly switch to presentation mode. This makes sure that whatever presentation I am doing I can always provide a decent experience showing code.