Ubuntu – Terminal command for checking/unchecking “Dim screen to save power”

brightnesscommand linescreen

I am having problems preventing my laptop, running Ubuntu 14.04, from dimming its screen when on battery power. I have tried everything that is out there on the internet to prevent this happening, but in vain. Most people solved their issue by unchecking the tick box beside "Dim screen to save power" in the "Brightness and lock" settings. I have tried that as well.

So is there any way to do this from the terminal?

Best Answer

You can get its status by using gsettings command as following:

gsettings get org.gnome.settings-daemon.plugins.power idle-dim

This will return "true" or "false". So if you want change its value use set option instead of get and type "true" to enable it or "false" to disable:

gsettings set org.gnome.settings-daemon.plugins.power idle-dim true

Now if you don't want to dim the screen when you are on battery power you need some scripting, because that setting doesn't detect or watch the state that if you are on ac-power or on battery mode.

This can be done by using on_ac_power command inside a while-loop to checking whether the system is running on AC power as following:

#!/bin/bash
while true
do
    if on_ac_power; then
        gsettings set org.gnome.settings-daemon.plugins.power idle-dim true
    else
        gsettings set org.gnome.settings-daemon.plugins.power idle-dim false
    fi
    sleep 60   # check the state in each 60 seconds
done

Save the script.ex: dimscreen.sh and run it by typing sh /path/to/dimscreen.sh in Terminal.


Also you can make it as a cron job in your crontab file.

#!/bin/bash
if on_ac_power; then
    gsettings set org.gnome.settings-daemon.plugins.power idle-dim true
else
    gsettings set org.gnome.settings-daemon.plugins.power idle-dim false
fi
  1. Saving the script (example dimscreen.sh)
  2. Make it executable chmod +x /path/to/dimscreen.sh
  3. open the crontab file by VISUAL=gedit crontab -e or EDITOR=gedit crontab -e

  4. Now copy and paste * * * * * /path/to/dimscreen.sh at end of it and save the file. This will run your command/script every minute

    .---------------- minute (0 - 59)
    |  .------------- hour (0 - 23)
    |  |  .---------- day of month (1 - 31)
    |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
    |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
    |  |  |  |  |
    *  *  *  *  * command to be executed