13

What I want is to be able to press:

Ctrl + Shift + 1 - switch to English keyboard layout
Ctrl + Shift + 2 - switch to Hebrew keyboard layout
Ctrl + Shift + 3 - switch to Russian(Phonetic) keyboard layout

I've seen similar questions already asked here, but only answers I saw used setxkbmap which breaks the UI keyboard layout selector, which is something undesired.

Thanks for any help.

lambda23
  • 3,232
Svarog
  • 171
  • As for as I know,

    Set "X" KeyboardBoard Map is already for the U.I. we are talking about. And the console U.I. alternative of setxkbmap should be loadkeys. What do you mean by saying "Breaks the UI"

    – Hilmi Erdem KEREN Oct 18 '12 at 14:08
  • 1
    @erdemkeren On the top right corner of the screen one of the buttons has a keyboard picture the code of currently selected keyboard layout. When clicked it shows a list of available layouts. Also, you can configure key combinations such as Alt+Shift to switch between those. Once you run setxkbmap this list is reset to include only the language you have just mentioned to setxkbmap. – Svarog Oct 18 '12 at 14:27
  • Did you try IBus. – saji89 Oct 21 '12 at 11:20
  • @saji89 Never heared about it before. Will take a look. Thanks. – Svarog Oct 21 '12 at 12:25
  • 1
    @saji89 I've tryed playing a bit with iBus, don't see how much it helps me. – Svarog Oct 21 '12 at 12:37

4 Answers4

1

If you are using Ubuntu you can set the default "Keyboard Layout" settings to change between keyboard layouts. However you cannot use the keyboard shortcuts you have listed. I do not know the way to do that.

If you open the system settings menu navigate to keyboard layout. Once open you will see your current keyboard layouts. If you click options and select "Key(s) to change layout, you can select which combo to change the layout. Some of the combos are

Alt+Caps Lock

Alt+Ctrl

Alt+Shift

Both Alt keys together, etc.

However thers is no way to set your own custom shortcuts. I attempted to see if there was possible a terminal code but there is no manual entry for Keyboard Layout settings, such as there is for other programs like Firefox: man firefoxIf there were you could easy create a custom key combo to run the command depending on which layout you want.

Additionally there is no indicator of which layout you've switched too and the only way to check is to type something. But it does seem to go in order of the way the layouts are listed.

Screen shot of the keyboard layout options menu

I hope that helps you.

snoop
  • 4,040
  • 9
  • 40
  • 58
  • Thanks for the information, but I've already known that, and this is not what I'm looking for. – Svarog Oct 20 '12 at 08:25
  • Please elaborate on what the difference is to what you want, what this answer describes and why you cannot use it. – jippie Oct 21 '12 at 19:16
  • @jippie - All those settings only allow to change the layout to the next layout. I.E. For example I have 3 keyboard layouts: English, Hebrew, Russian. If I'm currently typing in English, and then I press the selected keystroke, I'll move to Hebrew. Another keystroke - Russian. Next keystroke - back to English. What I'm looking for is a way to create 3 keystrokes that will switch me to English, Hebrew or Russian respectively, with no regard to which layout I'm currently on. a.k.a. Press Ctrl+Shift+3, and know for sure I'm typing in Russian now. – Svarog Oct 23 '12 at 11:09
  • Probably of little use to you, but in Kubuntu (KDE based) => Keyboard settings => Layout Allows me to configure a custom shortcut. Don't know if you can use de KDE settings tool, probably not. Are you sure there is no means of setting a custom shortcut? – jippie Oct 23 '12 at 18:19
0

The following solution works for Ubuntu 19.10.

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

Taken from here.

So just add key bindings you like with the index in the above command modified as desired (0 - your first layout, 1 - your second layout, and so on).

RobinBobin
  • 109
  • 2
0

In 2024, neither gsettings set org.gnome.desktop.input-sources current, nor gdbus call … org.gnome.Shell.Eval …" are working. They are deprecated. You could try to resurrect the Eval with ramottamado/eval-gjs, but it is unsafe as well.

So, I've made my own GNOME Shell Extension and I'm sharing it with the world: Shyriiwook (also available @ GitHub: madhead/shyriiwook).

This is a very simple, minimalist extension. It doesn't have any GUI. After installing it, a new D-Bus interface would be exposed in your GNOME Shell session. You could query it for the current configuration or call a method to activate the desired layout:

$ gdbus introspect \
    --session \
    --dest org.gnome.Shell \
    --object-path /me/madhead/Shyriiwook \
    --only-properties

node /me/madhead/Shyriiwook { interface me.madhead.Shyriiwook { properties: readonly as availableLayouts = ['us', 'de', 'jp']; readonly s currentLayout = 'us'; }; };

$ gdbus call
--session
--dest org.gnome.Shell
--object-path /me/madhead/Shyriiwook
--method me.madhead.Shyriiwook.activate "de"

This is easily scriptable, and you can even put this command raw into a custom shortcut under the "Settings" → "Keyboard" → "Keyboard Shortcuts" → "View and Customise Shortcuts" → "Custom Shortcuts".

madhead
  • 702
  • 3
  • 10
0
  1. Open "System Settings" > "Keyboard" > "Shortcuts" > "Custom Shortcuts"
  2. Press "+" to create a new one
  3. Add any name you like and the following command for the first layout: gsettings set org.gnome.desktop.input-sources current 0

  4. Press "Apply"

  5. Press on "Disabled" in right column for your key mapping
  6. Assign your hot key

Screenshot for step 3: enter image description here

Screenshot for step 5: enter image description here

Alexey
  • 109