random-wallpaper-gnome/change-wallpaper.py

57 lines
1.6 KiB
Python
Raw Normal View History

2025-02-04 01:51:58 +07:00
#!/usr/bin/python
import os
import random
import sys
2025-02-04 01:51:58 +07:00
if len(sys.argv) < 2 or sys.argv[1] == "":
print("Please specify a directory")
sys.exit()
2025-02-04 01:51:58 +07:00
# Specify the directory
directory_path = sys.argv[1]
2025-02-04 01:51:58 +07:00
def pick_random_file(directory):
# List all files in the specified directory
files = [f for f in os.listdir(directory) if os.path.isfile(os.path.join(directory, f))]
# Check if the directory is empty
if not files:
return None
# Pick a random file from the list
random_file = random.choice(files)
# Return the full path of the randomly picked file
return os.path.join(directory, random_file)
# Pick a random file
random_file_path = pick_random_file(directory_path)
if "blue" in random_file_path:
2025-02-04 01:51:58 +07:00
accent_color = "blue"
elif "teal" in random_file_path:
2025-02-04 01:51:58 +07:00
accent_color = "teal"
elif "green" in random_file_path:
2025-02-04 01:51:58 +07:00
accent_color = "green"
elif "yellow" in random_file_path:
2025-02-04 01:51:58 +07:00
accent_color = "yellow"
elif "orange" in random_file_path:
2025-02-04 01:51:58 +07:00
accent_color = "orange"
elif "red" in random_file_path:
2025-02-04 01:51:58 +07:00
accent_color = "red"
elif "pink" in random_file_path:
2025-02-04 01:51:58 +07:00
accent_color = "pink"
elif "purple" in random_file_path:
2025-02-04 01:51:58 +07:00
accent_color = "purple"
else:
accent_color = "slate"
print(f'INFO: Using background picture {random_file_path}')
print(f'INFO: Using accent color {accent_color}')
2025-02-04 01:51:58 +07:00
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.interface accent-color {accent_color}')