The accepted answer doesn't answer the question you asked, frankly.
You accepted a shortcut, but your question is - I think - mostly interpreted as looking for a command line solution.
That shorcut works, and your temporary solution in your comment under your question is almost perfect. Here is the command needed:
/bin/sleep 1 && /bin/dbus-send --session --print-reply --dest=org.kde.kglobalaccel /component/org_kde_powerdevil org.kde.kglobalaccel.Component.invokeShortcut string:'Turn Off Screen'
Basically, the difference compared to your solution:
- don't use qdbus command as it is deprecated (good distos ship it with some qt4 tool package still, but only with them, and they do not install it by default. Nor should most people install it...)
- you almost got the dbus method call right, but used a wrong shortcut and a hack with power button. It needed 2 minutes more in D-Bus viewer to find
"Turn Off Screen"
argument for invokeShortcut
And why would anyone need a command if there is a shortcut?
Because some people need a command for turning off screen together with screen locking
Anyway, thank for your answer, as it helped me a lot find the solution to this, and the latter question!!!
kcmshell5 powerdevilprofilesconfig
), one can setWhen power button pressed
toTurn off screen
. I guess this sends some special signal, which might also be callable via qdbus. I have now downladed the powerdevil kcm source code and try to investigate how it works – mara004 Feb 13 '21 at 12:59sleep 0.5 && qdbus org.kde.kglobalaccel /component/org_kde_powerdevil invokeShortcut "PowerOff"
. That works, but only if you have powerdevil configured to turn off the screen when the power button is pressed, so it's not particularly elegant... – mara004 Feb 13 '21 at 14:48