https://github.com/madhead/shyriiwook
Switch keyboard layouts programmatically!
https://github.com/madhead/shyriiwook
gnome gnome-extension gnome-shell gnome-shell-extension keyboard keyboard-layout keyboard-layout-switcher
Last synced: 6 months ago
JSON representation
Switch keyboard layouts programmatically!
- Host: GitHub
- URL: https://github.com/madhead/shyriiwook
- Owner: madhead
- License: mit
- Created: 2023-12-18T22:56:27.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2025-03-17T20:31:41.000Z (7 months ago)
- Last Synced: 2025-04-24T06:53:24.933Z (6 months ago)
- Topics: gnome, gnome-extension, gnome-shell, gnome-shell-extension, keyboard, keyboard-layout, keyboard-layout-switcher
- Language: JavaScript
- Homepage: https://extensions.gnome.org/extension/6691/shyriiwook
- Size: 172 KB
- Stars: 25
- Watchers: 4
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.adoc
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
= Shyriiwook
Switch keyboard layouts programmatically!
== The Problem
It's a shame that there is no easy way to switch keyboard input layout programmatically in Ubuntu (GNOME).
All the existing solutions are flawed in some way or another:* `gsettings set org.gnome.desktop.input-sources …`, found in many answers in the Internet is not working anymore in the latest Ubuntu versions.
* `setxkbmap …` doesn't play well with the GNOME Shell.
It switches the layout, but the UI doesn't reflect the change and you cannot switch languages with the keyboard shortcut anymore untill you restart.
* The `gdbus call … method org.gnome.Shell.Eval` is deprecated & disabled due to the security reasons with the `Eval` method.
* Finally, the `org.gnome.Shell.Shell.Eval` https://github.com/ramottamado/eval-gjs[replacement] is really sketchy, and it's essentially the same powerfulr `Eval` but from a third-party dev from GitHub.== The Solution
https://extensions.gnome.org/extension/6691/shyriiwook[Shyriiwook] is a GNOME Shell extension that allows to switch keyboard layouts programmatically.
The extension exposes a D-Bus interface, that could be used to query for the available layouts and to switch between them via `gdbus call …`.
However, it is programmed to only switch between the layouts, and does not expose a security breach like the `Eval` method.== Usage
First, install the extension.
You could find it in the https://extensions.gnome.org/extension/6691/shyriiwook[GNOME Extensions].
Just follow the instructions.Alternatively, you could use the https://github.com/mjakeman/extension-manager[Extension Manager] app to find `Shyriiwook` and install it from there.
Finally, you could <> the extension from the source code and install it manually.
After the extension is installed, you could use the `gdbus` tool to query for the available layouts and to switch between them.
To query for the available layouts, run:
[source, bash]
----
gdbus introspect --session --dest org.gnome.Shell --object-path /me/madhead/Shyriiwook --only-properties
----It will output something like this:
[source, bash]
----
node /me/madhead/Shyriiwook {
interface me.madhead.Shyriiwook {
properties:
readonly as availableLayouts = ['us', 'by+ru'];
readonly s currentLayout = 'us';
};
};
----These `availableLayouts` could be used to switch between the layouts, just pass one of them as an argument to the `activate` method:
[source, bash]
----
gdbus call --session --dest org.gnome.Shell --object-path /me/madhead/Shyriiwook --method me.madhead.Shyriiwook.activate "by+ru"
----The `currentLayout` property, obviously, contains the current layout.
That's it!
Now you could use those in your scripts, or even bind it to a keyboard shortcut in Gnome settings.
To do that, add a new custom shortcut with the `dbus call …` command under the "Settings" → "Keyboard" → "Keyboard Shortcuts" → "View and Customise Shortcuts" → "Custom Shortcuts".[#building]
== Building from sourceFirst, https://help.gnome.org/users/gnome-help/stable/gnome-version.html.en[determine] your GNOME version.
Starting from GNOME 45 some of the APIs used by the extension have changed, so you need to build the extension with the correct version.To build the extension, you need to have the Make build tool installed.
Then, just run:
[source, bash]
----
make 42 # To build for the GNOME 42
make 45 # To build for the GNOME 45
----The `build` directory will contain the extension in a corresponding subdirectory.
To build the extension ZIP archive, run:
[source, bash]
----
make extension-42
make extension-45
----If you want to tinker with the extension, you could symlink the directory to the extensions directory:
[source, bash]
----
ln -s $(pwd)/42 ~/.local/share/gnome-shell/extensions/shyriiwook@madhead.me
----To build and install the extension, you could run
[source, bash]
----
make install
----