1

Is there a way to access, set gnome system-settings from the command-line?

I'm specifically interested in a way to set:

settings -> energy -> screen off = never
settings -> energy -> screen off = (N) minue(s)

I would like to access this settings from a bash script, so I could set screen-off to never when the script starts and back to (N) minue(s) before the script exits.

I hope my question is clear, since I just translated the menu hierarchy from a German-GUI.

I tried to find a setting with gsettings but could not really get my way through.

1 Answer 1

3

ok, I found it, this is pretty nice since it's set in seconds you can also set a value shorter then a minute:

# Set "turn screen off" to (N)seconds:
  gsettings set org.gnome.desktop.session idle-delay N

# Set "turn screen off" to never:
  gsettings set org.gnome.desktop.session idle-delay 0

# Set "turn screen off" to 1 minute (60)seconds:
  gsettings set org.gnome.desktop.session idle-delay 60

In the script I use it as follows:

# getting the time of current setting and store to variable 'screenoff'
  screenoff=$(gsettings get org.gnome.desktop.session idle-delay \
               | awk '{print $2}')

# set "turn screen off" to never
  gsettings set org.gnome.desktop.session idle-delay 0

  echo "lots of important information being printed..."

# set back to the former setting:
  gsettings set org.gnome.desktop.session idle-delay "$screenoff"

the value stored into $screenoff would of course get lost if the script was canceled before completion.


A workaround could be to store the value to a temporary file, which gets removed at the very end of the script:

#!/bin/bash

# check if there is a temporary file from an aborted session
# read from this file or get value from gsettings & write temporay file:

  if [ -f "./.screenoff.tmp" ]; then
      screenoff=$(cat "./.screenoff.tmp")
  else
      screenoff=$(gsettings get org.gnome.desktop.session idle-delay \
                   | awk '{print $2}')
      echo "$screenoff" > "./.screenoff.tmp"
  fi

# switch power saving off:
  gsettings set org.gnome.desktop.session idle-delay 0

  echo "lots of important information being printed..."

# Set "turn screen off" back to original value:
  gsettings set org.gnome.desktop.session idle-delay "$screenoff"

# remove temporary file
  rm "./.screenoff.tmp"

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .