DEV Community

Cover image for Day 8 - Random Wallpaper Changer - 100 days 100 python scripts
Ganesh Raja
Ganesh Raja

Posted on

Day 8 - Random Wallpaper Changer - 100 days 100 python scripts

Day 8: update_gnome_wallpaper

This script will randomly select an image file from a folder of files and update the wallpaper in ubuntu

import os,random
import constants

WALLPAPER_DIR= constants.WALLPAPER_DIR # Wallpaper Location 

images=[item for item in os.listdir(WALLPAPER_DIR) if os.path.isfile(os.path.join(WALLPAPER_DIR,item)) and item.split(".")[-1].lower() in ["png",'jpg']]

if len(images) >0:
    wallpaper=random.choice(images)
    os.system("gsettings set org.gnome.desktop.background picture-uri file://"+os.path.join(WALLPAPER_DIR,wallpaper))
Enter fullscreen mode Exit fullscreen mode

Please Visit my Git Repo to check out all the previous day challenges.

https://github.com/ganeshraja10/automated-python-scripts

Top comments (0)