TransWikia.com

Switch between keyboard languages by CLI in GNOME

Ask Ubuntu Asked by user999598 on December 12, 2020

I’m looking for a way that I can switch keyboard language using Terminal.

input-sources

There already are some workarounds like setxkbmap us mentioned here.

But this is a workaround, and it does not do certain things (for example Ctrl+S stops working on non-English keyboards, and the language icon in the top-right corner of gnome does not change. This is why setxkbmap is not a solution).

2 Answers

Already added layouts:

If you already added input-sources via GUI.. get the list with below command

gsettings get org.gnome.desktop.input-sources sources

Example:

pratap@pratap:~$ gsettings get org.gnome.desktop.input-sources sources
[('xkb', 'se'), ('xkb', 'us'), ('xkb', 'ru'), ('xkb', 'de')]
pratap@pratap:~$

Count it from 0, 1, 2 & 3 Once you remember the numbering.. use the below command to change the input-sources (replace the number with your choice)

gdbus call --session --dest org.gnome.Shell --object-path /org/gnome/Shell --method org.gnome.Shell.Eval "imports.ui.status.keyboard.getInputSourceManager().inputSources[2].activate()"

Example:

pratap@pratap:~$ gdbus call --session --dest org.gnome.Shell --object-path /org/gnome/Shell --method org.gnome.Shell.Eval "imports.ui.status.keyboard.getInputSourceManager().inputSources[2].activate()"
(true, '')
pratap@pratap:~$

enter image description here

to add new layouts:

In the similar way, you can add new input-sources with gsettings set command, the order you want and count it from 0, 1, 2 & 3 etc..

and run the gdbus command to switch between input-sources..

Correct answer by UnKNOWn on December 12, 2020

List all possible languages:

gsettings get org.gnome.desktop.input-sources sources

Output:

[('xkb', 'se'), ('xkb', 'us'), ('xkb', 'ru'), ('xkb', 'de')]

To switch language to 'se' (0 - language index, in current case possible indexes 0-3):

gsettings set org.gnome.desktop.input-sources current 0

Answered by Maxim Akristiniy on December 12, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP