Last active
March 17, 2024 20:14
-
-
Save omamkaz/0269e6c7387991499ddb35f9ac0d822d to your computer and use it in GitHub Desktop.
Change plasma v5.24 accent color.
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
#!/usr/bin/python3 | |
from PIL import Image | |
import configparser | |
import subprocess | |
import sys | |
import os | |
def fetch_desktop_image() -> str: | |
path = "~/.config/plasma-org.kde.plasma.desktop-appletsrc" | |
path = os.path.expanduser(path) | |
config = configparser.ConfigParser() | |
config.read(os.path.expanduser("~/.config/plasma-org.kde.plasma.desktop-appletsrc")) | |
image = config.get("Containments][102][Wallpaper][org.kde.slideshow][General", "Image") | |
return image.removeprefix("file://") | |
def fetch_image_accent_color(image: str) -> str: | |
img = Image.open(image) | |
img = img.convert("RGB") | |
img = img.resize((300, 300)) | |
rgb = img.getpixel((150, 150)) | |
return '#' + ''.join(['{0:02x}'.format(int(x)) for x in rgb]) | |
def apply_accent_color(color: str) -> int: | |
return subprocess.run( | |
f"plasma-apply-colorscheme --accent-color '{color}'", | |
shell=True, | |
stderr=subprocess.DEVNULL, | |
stdout=subprocess.DEVNULL, | |
).returncode | |
def main(): | |
bg_image = fetch_desktop_image() | |
color = sys.argv[-1].strip().lower() if len(sys.argv) > 1 else fetch_image_accent_color(bg_image) | |
ok = apply_accent_color(color) | |
print("Color:", color) | |
print("OK:".rjust(6), ok) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment