Improve filename handling and do not hardcode paths

This commit is contained in:
Late Night Defender 2025-05-16 02:00:49 +07:00
parent 863d4c202d
commit 54c9cd1c62

View file

@ -2,9 +2,14 @@
import os import os
import random import random
import sys
if len(sys.argv) < 2 or sys.argv[1] == "":
print("Please specify a directory")
sys.exit()
# Specify the directory # Specify the directory
directory_path = '/path/to/your/wallpapers' directory_path = sys.argv[1]
def pick_random_file(directory): def pick_random_file(directory):
# List all files in the specified directory # List all files in the specified directory
@ -23,27 +28,27 @@ def pick_random_file(directory):
# Pick a random file # Pick a random file
random_file_path = pick_random_file(directory_path) random_file_path = pick_random_file(directory_path)
if random_file_path[-8:-4] == "blue": if "blue" in random_file_path:
accent_color = "blue" accent_color = "blue"
elif random_file_path[-8:-4] == "teal": elif "teal" in random_file_path:
accent_color = "teal" accent_color = "teal"
elif random_file_path[-8:-4] == "gree": elif "green" in random_file_path:
accent_color = "green" accent_color = "green"
elif random_file_path[-8:-4] == "yell": elif "yellow" in random_file_path:
accent_color = "yellow" accent_color = "yellow"
elif random_file_path[-8:-4] == "oran": elif "orange" in random_file_path:
accent_color = "orange" accent_color = "orange"
elif random_file_path[-8:-4] == "redd": elif "red" in random_file_path:
accent_color = "red" accent_color = "red"
elif random_file_path[-8:-4] == "pink": elif "pink" in random_file_path:
accent_color = "pink" accent_color = "pink"
elif random_file_path[-8:-4] == "purp": elif "purple" in random_file_path:
accent_color = "purple" accent_color = "purple"
else: else:
accent_color = "slate" accent_color = "slate"
# print(f'DEBUG: Using background picture {random_file_path}') print(f'INFO: Using background picture {random_file_path}')
# print(f'DEBUG: Using accent color {accent_color}') print(f'INFO: Using accent color {accent_color}')
os.system(f'gsettings set org.gnome.desktop.background picture-uri "file://{random_file_path}"') os.system(f'gsettings set org.gnome.desktop.background picture-uri "file://{random_file_path}"')
os.system(f'gsettings set org.gnome.desktop.background picture-uri-dark "file://{random_file_path}"') os.system(f'gsettings set org.gnome.desktop.background picture-uri-dark "file://{random_file_path}"')