I have managed to make this work inspired by the other answers. Unfortunately they were lacking some detail so instead will summarize the steps here for assigning keyboard shortcuts to a keyboard layout:
Make sure you already have installed all the desired keyboard layouts. They should be shown in the top bar when clicking the language button.
Download GNOME extension Eval-GJs: This extension is not on 'extensions.gnome.org', the official Gnome Shell Extensions website, so you must download / clone the repo from github.
Install the extension as a regular user as described in its README.md:
cd eval-gjs-main
make install
This will copy it to a folder within your home directory: ~/.local/share/gnome-shell/extensions
- Determine your gnome version by executing:
gnome-shell --version
- Edit metadata.json in
~/.local/share/gnome-shell/extensions/eval-gjs@ramottamado.dev/
Insert your exact gnome version in the array after the line "shell-version"
.
Log out, then log in again.
- Launch Extension manager (gnome-extensions-app)
Install it if you don't have it, with:
sudo apt install gnome-shell-extension-prefs
Enable the extension.
Note: the extension will not show up if your exact gnome version is not in metadata.json as explained above.
Create the following bash script change-layout.sh
and give it execute permissions :
#!/bin/bash
gsettings set org.gnome.desktop.input-sources current "$1"
gdbus call --session --dest org.gnome.Shell \
--object-path /dev/ramottamado/EvalGjs \
--method dev.ramottamado.EvalGjs.Eval \
"imports.ui.status.keyboard.getInputSourceManager().inputSources[$1].activate()"
- Test the script.
Run
change-layout.sh 0
for the first keyboard layout, in the case of OP this is English,
change-layout.sh 1
for the second layout, etc.
- Go to
Gnome settings -> Keyboard -> View and Customize shortcuts -> Custom Shortucts
, then assign your desire keyboard shortcut and use one of the commands above for the desired keyboard layout.