This post will shows how to set the numlock, or number lock, key to always be on or off using gsettings. Although it is based on Gnome 3.36 it should also allow you to discover where the settings are in other versions through the use of grep.
What are gsettings?
According to Gnome Developer gsettings is the Gsettings configuration tool which isn't much help at all. A better description might be gsettings is the command line tool that helps edit the hidden settings in Gnome. These settings can configured to either be true or false.
For example there is a graphical setting for disabling the touchpad while typing.
There is also a corresponding gsettings entry set to true.
org.gnome.desktop.peripherals.touchpad disable-while-typing true
Finding the right gsettings key
This part can be a little harder as sometimes you have to know what you are looking for before you can find it but you can list all the schemas with the command,
That will give you a long list that isn't hugely helpful either. More helpful can be a quick search on the internet, especially if you don't know the wording. In this case it is numlock but the only reason I know that is because the old program to set numberlock was called numlockx so I had a slight head start.
Search for numlock in gsettings with,
gsettings list-recursively | grep -e numlock
The first part of the commend lists all the settings possible in gsettings and the second part looks for the pattern given. In this case it gives the result,
org.gnome.desktop.peripherals.keyboard remember-numlock-state true org.gnome.desktop.peripherals.keyboard numlock-state true
This shows us what the keys containing numlock and what their values are. The first key asks whether the numlock state should be remembered and the second what the state is now. In both cases it is true so number lock is on and will stay on across logins and reboots.
How to change the gsettings numlock key
To change the gsettings numlock key from false to true use gsettings set,
gsettings set org.gnome.desktop.peripherals.keyboard numlock-state true
If you want this setting to be remembered then you also need to set the remember-numlock-state setting to true as well.
gsettings set org.gnome.desktop.peripherals.keyboard remember-numlock-state true
And that, is that.