Skip to content

Instantly share code, notes, and snippets.

@TheBlackParrot
Created December 6, 2016 06:43
Show Gist options
  • Save TheBlackParrot/82c1cb0db0fdbf01090f8a6bb48cf562 to your computer and use it in GitHub Desktop.
Save TheBlackParrot/82c1cb0db0fdbf01090f8a6bb48cf562 to your computer and use it in GitHub Desktop.
Wallpaper randomizer for wpgtk
#!/usr/bin/python
import subprocess
import os
import random
valid_extensions = [".jpg", ".png"]
wallpapers = []
output = subprocess.run("wpg -l".split(" "), stdout=subprocess.PIPE).stdout.decode("UTF-8")
for file in output.split("\n"):
if file[:2] == "::":
continue
filename, extension = os.path.splitext(file)
if extension in valid_extensions:
wallpapers.append(file)
choice = random.choice(wallpapers)
final_commands = [
"wpg -s {}".format(choice),
"i3-msg reload"
]
for cmd in final_commands:
subprocess.run(cmd.split(" "))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment