Skip to content

Instantly share code, notes, and snippets.

@Klhmt
Last active September 11, 2022 18:18
Show Gist options
  • Save Klhmt/8b46a2a7e9ddb3b60b084fac98ffe23c to your computer and use it in GitHub Desktop.
Save Klhmt/8b46a2a7e9ddb3b60b084fac98ffe23c to your computer and use it in GitHub Desktop.
Python Script To Change Randomly Gnome Wallpaper
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