0

GNOME Tweaks has a toggle to change the caps lock to ctrl:

enter image description here

How can I do either of the following via a bash script?

  • Toggle the setting so that I can see it enabled inside Tweaks
  • Just toggle the functionality (caps lock -> ctrl) itself, without changing the Tweaks setting
Ana
  • 113
  • 2

1 Answers1

0

To enable: gsettings set org.gnome.desktop.input-sources xkb-options "['caps:ctrl_modifier']"

To disable: gsettings set org.gnome.desktop.input-sources xkb-options "[]"

See also https://askubuntu.com/questions/971067/how-can-i-script-the-settings-made-by-gnome-tweak-tool

EDIT: To address Don's comment below you can run gsettings get org.gnome.desktop.input-sources xkb-options to see if any other xkb-options are already set. If there are you can incorporate them too in the gsetting command, for example you might have gsettings set org.gnome.desktop.input-sources xkb-options "['altwin:menu', 'caps:ctrl_modifier']"

Anthony Kelly
  • 294
  • 1
  • 4
  • Note that while both your commands work fine, they will delete any other `xkb` options already present... see my post [here](https://unix.stackexchange.com/a/212067)... so scripting this via shell is not that simple. An easier way imo is via `python`'s `Gio.Settings` – don_crissti Nov 28 '22 at 21:50
  • That's a fair point, @don_crissti. I've updated my answer to at least partially address this issue. – Anthony Kelly Nov 29 '22 at 09:47