Last active
May 3, 2019 22:15
-
-
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.
This file contains hidden or 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
#!/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