Reputation: 175
My goal is to make a script to apply a certain bundle of settings all at once to my computer if something specific happens. I am currently stuck, at how to change the Windows color theme. I could figure out how to change the theme from light to dark and reverse using this code:
import subprocess
command = ['reg.exe', 'add', 'HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize',
'/v', 'AppsUseLightTheme', '/t', 'REG_DWORD', '/d', '0', '/f']
subprocess.run(command)
This code works, and I can use it to change from light to dark theme. But there are also other settings in this settingsboundle:
I want to be able to change color accent, like in this image there is blue selected, to another color (for example red). I could not find any way to do this, nor how to universally change Windows settings.
Do you know any way of changing the Windows color accent using Python?
Do you know of any way to change any Windows setting (such as the background, mouse cursor size, font, font size), perhaps is there even a module to it which can be used like in the following mock example:
import example
setting2 = windows.CURSOR_SIZE
setting2v = 15
example.change.setting(setting2, setting2v)
print("succesfully changed setting " + str(setting2) + " to value " + str(setting2v))
Upvotes: 4
Views: 1672
Reputation: 3828
You are looking for running PowerShell commands using Python.
First, find out the needed command, there is probably a command for every action you want in Windows.
Then, you can do it as follows:
import subprocess
hideBar = "&{$p='HKCU:SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\StuckRects3';$v=(Get-ItemProperty -Path $p).Settings;$v[8]=3;&Set-ItemProperty -Path $p -Name Settings -Value $v;&Stop-Process -f -ProcessName explorer}"
def run(cmd):
subprocess.run(["powershell", "-Command", cmd])
run(hideBar)
Reference: How to change a certain windows setting using python?
Upvotes: 2
Reputation: 10136
There's no Python module that makes it that easy to tweak Windows UI settings programmatically. But you already have a working example of using reg.exe from Python. You can use your working example as a basis for modifying other registry settings. Now it's just a matter of locating the appropriate registry keys for the settings you want to change. You can do this using Google, example search query: registry key for personalize accent color
.
Here's a StackExchange post going over the keys for many Personalize settings:
https://superuser.com/a/1395560/54746
Upvotes: 1