Skip to content

Instantly share code, notes, and snippets.

@defvol
Last active May 3, 2019 22:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save defvol/842823331c9efb889f701582da20e46b to your computer and use it in GitHub Desktop.
Save defvol/842823331c9efb889f701582da20e46b to your computer and use it in GitHub Desktop.
A cron-ready script for choosing a random wallpaper on a GNOME desktop. Some ideas borrowed from https://github.com/thedevsaddam/ubuntu-live-wallpaper and crontab.guru.
#!/usr/bin/python
# usage: random-wallpaper.py <directory>
from os import environ, listdir, system
from os.path import isfile, join
import random
import sys
environ['GIO_EXTRA_MODULES'] = '/usr/lib/x86_64-linux-gnu/gio/modules/'
# Scan directory
directory = sys.argv[1]
files = [f for f in listdir(directory) if isfile(join(directory, f))]
# Choose a file
chosen = random.choice(files)
filepath = join(directory, chosen)
print("Setting wallpaper: " + filepath)
# Update wallpaper
command = "gsettings set org.gnome.desktop.background picture-uri file:///{}".format(filepath)
system(command)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment