Last active
May 26, 2019 19:10
-
-
Save urandom/a51cdacab2522ff8ae32c7c22e79039e to your computer and use it in GitHub Desktop.
Change gnome3's wallpaper from a random one in a directory
This file contains 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/python3 | |
import os | |
import random | |
import subprocess | |
import sys | |
import urllib.request, urllib.parse, urllib.error | |
from os.path import isfile, join | |
if len(sys.argv) == 1: | |
raise RuntimeError("No wallpaper path") | |
path = sys.argv[1] | |
wallpapers = [f for f in os.listdir(path) if isfile(join(path, f))] | |
wallpaper = random.choice(wallpapers) | |
wallpaper = urllib.parse.quote(join(path, wallpaper)) | |
subprocess.check_call(["/usr/bin/gsettings", "set", "org.gnome.desktop.background", "picture-uri", "file://{}".format(wallpaper)]) | |
subprocess.check_call(["/usr/bin/gsettings", "set", "org.gnome.desktop.screensaver", "picture-uri", "file://{}".format(wallpaper)]) |
This file contains 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
*/10 * * * * DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus DISPLAY=:0 ~/.local/bin/change-wallpaper /usr/share/wallpapers |
This file contains 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
[Unit] | |
Description=Rotate GNOME background | |
[Service] | |
Type=oneshot | |
Environment=DISPLAY=:0 | |
Environment=DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus | |
ExecStart=~/.local/bin/change-wallpaper /usr/share/wallpapers | |
[Install] | |
WantedBy=basic.target |
This file contains 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
[Unit] | |
Description=Rotate GNOME wallpaper timer | |
[Timer] | |
OnCalendar=*:0/10 | |
Persistent=true | |
Unit=gnome-background-change.service | |
[Install] | |
WantedBy=gnome-background-change.service |
This file contains 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
systemctl --user enable gnome-background-change.timer | |
systemctl --user start gnome-background-change.timer |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment