Last active
May 13, 2017 14:41
-
-
Save nand0p/4a4b88e848c71df53ec1e4d8ca4c1318 to your computer and use it in GitHub Desktop.
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/env python | |
import os | |
import random | |
import subprocess | |
from textwrap import dedent | |
image_dir = "/home/nando/Pictures/nasa" | |
def get_wallpaper(image_dir): | |
image = random.choice(os.listdir(image_dir)) | |
image_path = os.path.join(image_dir, image) | |
print(image_path) | |
return(image_path) | |
def make_dbus_script(image_path): | |
dbus_script = dedent('''\ | |
var Desktops = desktops(); | |
for (i=0;i<Desktops.length;i++) {{ | |
d = Desktops[i]; | |
d.wallpaperPlugin = "org.kde.image"; | |
d.currentConfigGroup = Array("Wallpaper", "org.kde.image", "General"); | |
d.writeConfig("Image", "file://{}") | |
}} | |
''').format(image_path) | |
print(dbus_script) | |
return(dbus_script) | |
def set_wallpaper(dbus_script): | |
subprocess.Popen([ | |
'dbus-send', | |
'--session', | |
'--dest=org.kde.plasmashell', | |
'--type=method_call', | |
'/PlasmaShell', | |
'org.kde.PlasmaShell.evaluateScript', | |
'string:{}'.format(dbus_script) | |
]) | |
image_path = get_wallpaper(image_dir) | |
dbus_script = make_dbus_script(image_path) | |
set_wallpaper(dbus_script) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment