0

I'm very new to KDE (running Kubuntu 18.10) and want to be able to quickly toggle grayscale through the terminal. I can make the script to do this but I don't know what to call to toggle the Desktop Effect.

Currently I'm using the extension described in this answer from this Github reop. Everything works great, the only problem is that I want to quickly switch to grayscale instead of going into System Settings > Desktop Behavior >Desktop Effects and click Apply. This is way to many steps for me to use more than once or twice a day.

My question is what command do I call to toggle this from the command line so I can write a script to do this?

I'm looking at the qdbus and trying something like:

qdbus org.kde.KWwin /Effects toggleEffect Grayscale

But nothing happens.

fizzyh2o
  • 103
  • 4
  • Thanks, yes, that quirk was present but everything works fine once I applied the Desktop Effects with Grayscale off and on. I'm reading up on how KWin extension work so might get somewhere. – fizzyh2o Mar 19 '19 at 06:23
  • 1
    When you toggle the Grayscale effect, changes are written to ~/.config/kwinrc in the [Plugins] section. Specifically, toggling changes kwin4_effect_grayscaleEnabled=false to kwin4_effect_grayscaleEnabled=true or vice versa. If you don't use the default GUI, but use the command line (or a script) using kwriteconfig5 --file ~/.config/kwinrc --group Plugins --key kwin4_effect_grayscaleEnabled "false" (or "true"), you need to reload KWin to effect the change. kwin_x11 --replace & disown reloads KWin but may make the system unstable! There maybe a better way of which I'm not aware. – DK Bose Mar 19 '19 at 10:20
  • In short, my experience of not using the default GUI isn't a happy one! – DK Bose Mar 19 '19 at 10:21
  • 1
    There's also qdbus org.kde.KWin /KWin reconfigure which I found here but haven't tried. zren is a KDE developer. – DK Bose Mar 19 '19 at 10:27
  • Thanks. A combination of kwriteconfig and /KWin reconfigure worked well! – fizzyh2o Apr 09 '19 at 08:06

2 Answers2

1

This doesn't deserve an answer, but I don't have the reputation to comment.

I'm trying to automate grayscale toggling via a shortcut too, and sometimes the set:

kwriteconfig5 --file ~/.config/kwinrc --group Plugins --key kwin4_effect_grayscaleEnabled "false"
qdbus org.kde.KWin /KWin reconfigure

doesn't work (effect is not disabling, even if visibly unchecked in the settings).

So I just add an extra line:

qdbus org.kde.KWin /Compositor suspend && qdbus org.kde.KWin /Compositor resume

(it reloads the compositor, the same as doing "alt+shift+F12" twice)

And this allows to avoid the heavy kwin_x11 --replace solution, so I think it's better (but I'm absolutely no expert here).

(Note that I had to add a sleep 0.2 in between the two lines too, otherwise the grayscale disabling didn't work unless I triggered the whole thing a second time)

NoGa
  • 26
1

If you are still interested in the DBUS answer, which its a bit less complicated, you can try this:

#Enable the Effect:
qdbus --literal org.kde.KWin /Effects org.kde.kwin.Effects.loadEffect kwin4_effect_grayscale

#Disable the Effect: qdbus --literal org.kde.KWin /Effects org.kde.kwin.Effects.unloadEffect kwin4_effect_grayscale

#Toggle the Effect state: qdbus --literal org.kde.KWin /Effects org.kde.kwin.Effects.toggleEffect kwin4_effect_grayscale

  • loadEffect isn't "get the effect status," it enables it. It also returns true if it loaded it or false if it was already loaded.

    There's also org.kde.kwin.Effects.unloadEffect to disable it.

    – nafg Jan 18 '24 at 04:01