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".