Querying and applying settings using gsettings
3 min read

Querying and applying settings using gsettings

Recently I had a need to adjust my power settings via the terminal since I was working on  a rice that at the time, didn't have any power settings applet or widget. If I stepped away from my computer for 5 minutes it would enter into stand-by and due to the "in progress" state of my environment - I had no way to wake it besides hitting the nuke button.

Enter gsettings. gsettings allows you to configure many aspects of your system via the terminal. It's a very powerfull tool once you learn how to use it.

gsettings uses a SCHEMA and KEY approach to settings, and allows you to GET or SET said keys.

The initial problem i had was to figure out which schema I needed to adjust for power settings. gsettings has a switch list-schemas so I gave that a try;

com.canonical.Unity.Lenses
com.canonical.unity.desktop.background
com.canonical.unity.desktop.interface
com.canonical.unity.desktop.screensaver
com.gexperts.Tilix.Keybindings
com.gexperts.Tilix.ProfilesList
com.gexperts.Tilix.Settings
com.ubuntu.SoftwareProperties
com.ubuntu.login-screen
com.ubuntu.notifications.hub
com.ubuntu.notifications.settings.applications
com.ubuntu.phone
com.ubuntu.sound
com.ubuntu.touch.network
com.ubuntu.touch.sound
com.ubuntu.touch.system
com.ubuntu.update-manager
com.ubuntu.update-notifier
com.ubuntu.user-interface
com.ubuntu.user-interface.desktop
net.flyingpimonster.Camera
org.freedesktop.ColorHelper
org.freedesktop.Tracker3.Extract
org.freedesktop.Tracker3.FTS
org.freedesktop.Tracker3.Miner.Files
org.freedesktop.ibus
org.freedesktop.ibus.general
...

Welp... that list is truncated, and it's LONG! But still, thats one peice of the puzzel I required: org.gnome.settings-daemon.plugins.power is the schema i want to adjust, but what about the key?

To find the key, we can use the schema and query it's keys with the following command:

gsettings list-keys org.gnome.settings-daemon.plugins.power

Which gave me the following:

ambient-enabled
idle-brightness
idle-dim
lid-close-ac-action
lid-close-battery-action
lid-close-suspend-with-external-monitor
power-button-action
power-saver-profile-on-low-battery
sleep-inactive-ac-timeout
sleep-inactive-ac-type
sleep-inactive-battery-timeout
sleep-inactive-battery-type

NICE! Now lets check to see what my sleep-inactive-ac-timeout is set to:

$ gsettings get org.gnome.settings-daemon.plugins.power sleep-inactive-ac-timeout
$ 900

So my idle timeout is set to 900 seconds, or 15 minutes. I my computer never to go into standby (this things powers on so quick if i'm done, i just power it down) so lets set it to 0.

$ gsettings set org.gnome.settings-daemon.plugins.power sleep-inactive-ac-timeout 0

Done! Now my PC will never go to sleep unless I tell it to.


To help with this in future I created a bash script to help navigating the SCHEMA and KEYS in gsettings a little easier:

#!/bin/bash

for schema in $(gsettings list-schemas | sort )
do
	for key in $(gsettings list-keys $schema | sort)
	do
		value="$(gsettings range $schema $key | tr "\n" " ")"
		echo "$schema :: $key :: $value"
	done
done

This script can by used by invoking it, then using grep to find the key you're looking for. Again, in the case of power settings:

$ gsettings-helper.sh | grep power
$ org.gnome.power-manager :: info-history-graph-points :: type b 
org.gnome.power-manager :: info-history-graph-smooth :: type b 
org.gnome.power-manager :: info-history-time :: type i 
org.gnome.power-manager :: info-history-type :: type s 
org.gnome.power-manager :: info-last-device :: type s 
org.gnome.power-manager :: info-page-number :: type i 
org.gnome.power-manager :: info-stats-graph-points :: type b 
org.gnome.power-manager :: info-stats-graph-smooth :: type b 
org.gnome.power-manager :: info-stats-type :: type s 
org.gnome.settings-daemon.plugins.media-keys :: power :: type as 
org.gnome.settings-daemon.plugins.media-keys :: power-static :: type as 
org.gnome.settings-daemon.plugins.power :: ambient-enabled :: type b 
org.gnome.settings-daemon.plugins.power :: idle-brightness :: type i 
org.gnome.settings-daemon.plugins.power :: idle-dim :: type b 
org.gnome.settings-daemon.plugins.power :: lid-close-ac-action :: enum 
org.gnome.settings-daemon.plugins.power :: lid-close-battery-action :: 
org.gnome.settings-daemon.plugins.power :: lid-close-suspend-with-
org.gnome.settings-daemon.plugins.power :: power-button-action :: enum 
org.gnome.settings-daemon.plugins.power :: power-saver-profile-on-low-
org.gnome.settings-daemon.plugins.power :: sleep-inactive-ac-timeout :: 
org.gnome.settings-daemon.plugins.power :: sleep-inactive-ac-type :: enum 'blank' 'suspend' 'shutdown' 'hibernate' 'interactive' 'nothing' 
org.gnome.settings-daemon.plugins.power :: sleep-inactive-battery-
org.gnome.settings-daemon.plugins.power :: sleep-inactive-battery-type 

I've truncated some of the results there but you get the idea, i can now easily see org.gnome.settings-daemon.plugins.power is my schema and the key i'm looking for is sleep-inactive-ac-timeout

Hope this helps!