Last active
September 11, 2022 18:18
-
-
Save Klhmt/8b46a2a7e9ddb3b60b084fac98ffe23c to your computer and use it in GitHub Desktop.
Python Script To Change Randomly Gnome Wallpaper
This file contains 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
from os import system, listdir | |
from random import randint | |
def changeWallpaper(wallpaper_path: str): | |
"""This function changes the wallpaper of your Gnome desktop | |
Arg: | |
wallpaper_path (str): path of the a folder that contains your wallpaper | |
""" | |
# Allowed image extensions | |
extensions = ("jpg", "png", "jpeg") | |
# Selection of images according to their extension | |
wallpaper_images = [image for image in listdir(wallpaper_path) if image.split(".")[-1] in extensions] | |
# Random choice of an image | |
selected_image = wallpaper_images[randint(0, len(wallpaper_images) - 1)] | |
# Apply a new wallpaper | |
system("gsettings set org.gnome.desktop.background picture-uri file:///{}".format(wallpaper_path + "/" + selected_image)) | |
changeWallpaper("/your/directory/") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment