1

I'd like to write a program in F# to change the wallpaper on Linux. It seems like I need to use dbus and JS to do that in KDE and I'm a bit confused about it.
I found this, and tried running qdbus org.kde.plasmashell /PlasmaShell org.kde.PlasmaShell.evaluateScript ~/scripts/wallpaper.js, where wallpaper.js is as follows:

var allDesktops = desktops();
print (allDesktops);

for (i=0;i<allDesktops.length;i++) {
    d = allDesktops[i];
    d.wallpaperPlugin = "org.kde.image";
    d.currentConfigGroup = Array("Wallpaper", "org.kde.image", "General");
    d.writeConfig("Image", "file:///home/amino/Pictures/wallpapers/wallhaven-360156.jpg")
}

But I get this error:
Error: org.freedesktop.DBus.Error.Failed SyntaxError: Invalid regular expression: invalid regular expression

Is there a better way to do this? If not, what would be the correct way to do what I'm trying to do?

Cœur
  • 37,241
  • 25
  • 195
  • 267
ohmree
  • 375
  • 3
  • 15
  • The fastest way is the `kwriteconfig` or `kwriteconfig5` command-line tool. I don't use KDE, so can't tell if it works. (https://askubuntu.com/questions/839647/gsettings-like-tools-for-kde) – Velkan Jul 31 '17 at 07:35

1 Answers1

2

This is my first time answering a question on here, so apologies if it's not quite right. I believe the only thing that might be wrong with your JS code is perhaps it needs additional single quotes and maybe adding 'file://' is unnecessary.

- d.writeConfig("Image", "file:///home/amino/Pictures/wallpapers/wallhaven-360156.jpg")
+ d.writeConfig("Image", "'file:///home/amino/Pictures/wallpapers/wallhaven-360156.jpg'")

For additional info this is the script I use:

#!/bin/bash
WALLPAPERDIR="/pathtodir/"

qdbus org.kde.plasmashell /PlasmaShell org.kde.PlasmaShell.evaluateScript 'var allDesktops = desktops();

print (allDesktops);for (i=0;i<allDesktops.length;i++) {
d = allDesktops[i];d.wallpaperPlugin = "org.kde.slideshow";
d.currentConfigGroup = Array("Wallpaper", "org.kde.slideshow", "General");
d.writeConfig("SlidePaths", "'${WALLPAPERDIR}'")}'

This works absolutely flawlessly.