This forum has been archived. All content is frozen. Please use KDE Discuss instead.

[SOLVED for power]Changing system settings from CLI

Tags: None
(comma "," separated)
User avatar
sparhawk
Registered Member
Posts
433
Karma
0
OS
Apologies if this has been discussed before, but I couldn't find it anywhere (although I suspect it's not an uncommon request). I'm looking for a way to change system settings from the command line, specifically Energy Saving (suspend) options. I'd like a script to be able to inhibit sleep. This is the equivalent to unchecking the "suspend session" box in the Energy Saving panels. (It'd also be great to change screensaver settings, too.)

Thanks in advance.

Last edited by sparhawk on Sun Dec 23, 2012 3:24 am, edited 3 times in total.
User avatar
toad
Global Moderator
Posts
1258
Karma
7
OS
Good call.

I've seen a thread here and there but only the odd snippet.

Be great if this could serve as a pool and perhaps even encourage some decent documentation.

I'd be glad to add to the wiki :)


Debian testing
luebking
Karma
0
Code: Select all
kwriteconfig --file powermanagementprofilesrc --group AC/SuspendSession --key idleTime 86400000
kwriteconfig --file powermanagementprofilesrc --group AC/SuspendSession --key suspendType 0


this alters the configuration files FOR THE AC PROFLE (there's also Battery and LowBattery or similar) and sets the timeout to a day (deactivation deletes the key, but that's not possible with kwriteconfig)

Code: Select all
qdbus org.kde.kded /kded reconfigure


will reconfigure the ded, but i've no idea whether that implicitly reconfigured all modules as well.

However, if you actually want to (temporarily) block all powersavings (because the screen dims during a video presentation etc.) you might want to try

Code: Select all
qdbus org.kde.kded /kded unloadModule powerdevil


and later on

Code: Select all
qdbus org.kde.kded /kded loadModule powerdevil
User avatar
sparhawk
Registered Member
Posts
433
Karma
0
OS
Thanks again for the helpful reply, luebking.

It seems that the first suggestion doesn't work (for me), but the second suggestion does. It's not exactly what I asked for, but it does solve my problem perfectly. Thanks!

Also, do you know if this is a global setting (i.e. for all users)? i.e. if I use this command as root from a udev script, will it prevent suspension for users too?

Cheers.
luebking
Karma
0
no, qdbus operates on the session bus, thus effectively "per user".
Also you have to export the correct DISPLAY variable (usually "DISPLAY=:0")

However, the superuser can oc. feign to be any other user, ie. you put that stuff into a script and run it "sudo -u $USER powerToggle.sh"
"users" is gonna tell you who's logged in, the rest ist BashFu =)
User avatar
sparhawk
Registered Member
Posts
433
Karma
0
OS
Excellent! Thanks. That does seem to work fine.
User avatar
sparhawk
Registered Member
Posts
433
Karma
0
OS
A bit of an update: it seems that the scope of the power module is a bit greater than I realised. One of the reasons I want to stop the computer from suspending is to run long tasks, often overnight (for example, backing up, building something, processor-intensive jobs, etc.). I'd like to be able to reduce the screen brightness while preventing the computer from going to sleep, but it seems that disabling the power module also prevents reducing the brightness.

I can do `xset dpms force off`, but if someone bumps the mouse (for example), then the screen stays on all night.

OTOH, in gnome I was able to use `gsettings` to set the screen to sleep at 1 second, while preventing the computer from suspending to RAM.
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS
Unfortunately Powerdevil is responsible for handling the turning off of the screen to the best of my knowledge after a certain amount of time.
Instead of unloading Powerdevil, does running the following cause it to reload it's configuration?
Code: Select all
qdbus org.kde.kded /org/kde/Solid/PowerManagement reparseConfiguration


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]
User avatar
sparhawk
Registered Member
Posts
433
Karma
0
OS
Thanks for the reply. Unfortunately, it doesn't seem to work either. From luebking's suggestion above, it seems that an idleTime of 1000 is equivalent to 1 second. First, I tried to set the time to a minute via the GUI, and it worked with good precision. I quit system settings, then tried again with the following code, but nothing happened after a minute.
Code: Select all
kwriteconfig --file powermanagementprofilesrc --group AC/SuspendSession --key idleTime 60000
qdbus org.kde.kded /org/kde/Solid/PowerManagement reparseConfiguration
luebking
Karma
0
You don't need powerdevil to (automatically) sleep the screen nor in many cases to alter brightness.

For brightness just see whether xbacklight works (simpler than writing into the backlight device and does not require root permissions. There's also a "backlighthelper" tool in /usr/lib/kde4/libexec, but i don't know the paramters atm.

For dpms control, check "xset -q" to see the current state.
Then use eg "xset dpms 360 420 480; xset +dpms" to set dpms to standby after 6 minutes, suspend after 7 and off after 8
"xset +dpms" activates dpms, "xset -dpms" DEactivates it - you could also just power off the screen by hand btw. In doubt saves even more energy.


From my experience every loading of powerdevil will simply disable X11 dpms, so you got to re-activate (and perhaps re-setup) it as well with this.
User avatar
sparhawk
Registered Member
Posts
433
Karma
0
OS
Great! xset is a good workaround.

Using xbacklight isn't really a great option, because if I set the brightness to 0 by hand, I'd have to type into a blank screen to reset it. I suppose I could assign it to a shortcut key, but I imagine xset probably turns the screen off "more". Also, it's a laptop, so I can't turn the screen off by hand.

What's interesting is that I don't think reloading the powerdevil resets dpms.
Code: Select all
$ qdbus org.kde.kded /kded unloadModule powerdevil > /dev/null
$ xset -q
# <--snip-->
DPMS (Energy Star):
  Standby: 0    Suspend: 0    Off: 0
  DPMS is Disabled
$ xset dpms 10 15 20; xset +dpms
$ xset -q
# <--snip-->
DPMS (Energy Star):
  Standby: 10    Suspend: 15    Off: 20
  DPMS is Enabled
  Monitor is On
$ qdbus org.kde.kded /kded loadModule powerdevil > /dev/null
$ xset -q
# <--snip-->
DPMS (Energy Star):
  Standby: 540    Suspend: 810    Off: 1080
  DPMS is Enabled
  Monitor is On


From that, it seems that when I re-enabled powerdevil, now xset is also operational?

----EDIT (more testing)

Okay, so I think I've got it partially figured out. It seems that dpms is the means by which KDE applies power-saving to the screen. Hence, if I unload/reload powerdevil, then dpms will turn off/on. In addition, I can manually turn dpms on/off using `xset +dpms` or `xset -dpms`. (While powerdevil is loaded) if I modify the KDE system settings (screen energy savings), it will turn on dpms if previously off. That all seems to make sense now. Essentially, the state of dpms is controlled by the powerdevil (and KDE system settings), although it can be controlled separately.

The only strange thing is that if I load the KDE dpms settings (either through the GUI or reloading powerdevil), it sets the standby setting to whatever is in the GUI, but the suspend value to 150% of standby, and the off value to 200% of standby. From googling, there's probably no difference between the three states for my laptop lcd, but I did think it was a little odd.

Thanks again!
User avatar
sparhawk
Registered Member
Posts
433
Karma
0
OS
Hmmm... One more question...

In order to keep my dpms settings consistent when unloading powerdevil, I'm trying to read KDE settings, by using kreadconfig. I cannot work out how to quote the name of the group. I've worked out that the --file is located in ~/.kde/share/config/ , but do not know how to refer to "[AC][DPMSControl]". For example, the following does not work.
Code: Select all
kreadconfig --file powermanagementprofilesrc --group [AC][DPMSControl] --key idleTime


I've noticed that previously in this thread, luebking suggested using
Code: Select all
kwriteconfig --file powermanagementprofilesrc --group AC/SuspendSession --key idleTime 86400000


However, when I look at ~/.kde/share/config/powermanagementprofilesrc , I can now see two groups, "[AC][SuspendSession]" and "[AC/SuspendSession]". When I change KDE sleep settings via the GUI, the former changes. I wonder if the reason why none of our previous troubleshooting worked was that the latter did not refer to anything present previously, and we actually mis-quoted the name of the setting?
luebking
Karma
0
Yes, and yes, my bad.
Use
kreadconfig --file powermanagementprofilesrc --group AC --group DPMSControl --key idleTime
User avatar
sparhawk
Registered Member
Posts
433
Karma
0
OS
Ah thanks. Just for some more closure, I tested kwriteconfig again with both pairs of new settings, but neither worked. For good measure I tried both possible methods of reloading the configuration. That is, I tried
Code: Select all
kwriteconfig --file powermanagementprofilesrc --group AC --group DPMSControl --key idleTime 5
qdbus org.kde.kded /kded reconfigure
qdbus org.kde.kded /org/kde/Solid/PowerManagement reparseConfiguration

and
Code: Select all
kwriteconfig --file powermanagementprofilesrc --group AC --group SuspendSession --key idleTime 60000
qdbus org.kde.kded /kded reconfigure
qdbus org.kde.kded /org/kde/Solid/PowerManagement reparseConfiguration

and neither worked after waiting a minute. Interestingly enough, after the first line in both cases (`kwriteconfig`), I could see the new settings when I opened up the KDE system settings GUI (in the first case rounded up to 1 minute).

Anyway, this is just really FYI, since I have a perfectly functional workaround unloading powerdevil and re-enabling dpms (in fact, it's probably cleaner). Thanks again for all your help.


Bookmarks



Who is online

Registered users: Baidu [Spider], Bing [Bot], Google [Bot]