Last active
August 27, 2025 15:59
-
-
Save lucivaldo/0fc5167e245d5eea2d975c01aa3cec7f to your computer and use it in GitHub Desktop.
Script Python para alterar o wallpaper
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/env python3 | |
| import glob | |
| import os | |
| import random | |
| import time | |
| import subprocess | |
| from pathlib import Path | |
| PICTURES_PATH = os.path.join(os.path.expanduser("~"), "Pictures") | |
| WALLPAPERS_PATH = os.path.join(PICTURES_PATH, "Wallpapers") | |
| def _gsettings_get(schema: str, key: str) -> str | None: | |
| try: | |
| out = subprocess.check_output( | |
| ["gsettings", "get", schema, key], | |
| stderr=subprocess.STDOUT, | |
| text=True | |
| ).strip() | |
| return out.strip().strip("'") | |
| except Exception: | |
| return None | |
| def is_dark_mode() -> bool: | |
| cs = _gsettings_get("org.gnome.desktop.interface", "color-scheme") | |
| if cs: | |
| return "prefer-dark" in cs | |
| theme = _gsettings_get("org.gnome.desktop.interface", "gtk-theme") | |
| return bool(theme and "dark" in theme.lower()) | |
| def choose_wallpaper() -> str | None: | |
| wallpapers = [p for p in glob.glob(WALLPAPERS_PATH + "/**/*", recursive=True) if os.path.isfile(p)] | |
| if not wallpapers: | |
| return None | |
| return random.choice(wallpapers) | |
| while True: | |
| dark = is_dark_mode() | |
| key = "picture-uri-dark" if dark else "picture-uri" | |
| wallpaper = choose_wallpaper() | |
| if wallpaper: | |
| uri = Path(wallpaper).as_uri() | |
| cmd = f'gsettings set org.gnome.desktop.background {key} "{uri}"' | |
| os.system(cmd) | |
| time.sleep(5 * 60) # 5 minutos |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment