Setting keyboard layouts programmatically
I have the following bash script in Debian 9/Gnome:
Code:
#!/bin/bash 2) Where can I find the abbreviations for the variants of a given language? |
I have no idea if these are the commands required to change keyboard layout in GNOME. Do they work when invoked 1 by 1, manually?
Can't you just use "setxkbmap" instead? The 2-letter codes are here |
You should definitely use setxkbmap. See the man page and also Arch guide. Look at the language file in /usr/share/X11/xkb/symbols/ to see the variant names, like "alternative" or "Dvorak" in "fr".
|
Programmatically executing the script, manually executing it or manually running the individual commands have all the same behavior. They all show the desired layouts but the setting of the "current" one is without effect.
Yes, I can set one layout at a time but the last set overrides the previous one, and that led me to the following workaround (eliminating some useless double quotes): Code:
#!/bin/bash I will definitely look at "setxkbd" as suggested, it looks like "localectl" could be the easiest. Thank you all. |
Actually, setxkbmap is only relevant if you run GNOME under Xorg/X11.
Quote:
Quote:
|
Quote:
|
Quote:
What I meant is that setxkbmap only works under X11/Xorg. That's what I'm talking about; but I see how the phrasing could be ambiguous if one didn't read everything carefully. |
On a Debian 10, Gnome, Kernel 5.9 I've tried this:
Code:
#!/bin/bash |
You didn't show us the output!
Also, run every command verbose. I'm not a fan of GNOME and don't know much about its inner workings. It's quite possible that as a desktop environment it thinks it should override these setting somehow. :shrugs: Also you didn't clarify whether you run under X or wayland. If the latter, setxkbmap will be useless, I think. |
Well, this is what I get on GNOME 2.32 (I highlighted red the relevant part):
Code:
$ gsettings describe org.gnome.desktop.input-sources current |
ondoho,
sorry for the lapse. Here is the ouput with a reduced number of commands typed individually: Code:
$ setxkbmap -layout ch -variant fr -verbose |
hruggy,
with the command you suggested on GNOME 3.30.2 I get the exact same message. That answers the first question in my original post. I've found the answer to my second question with a list of layouts and this command explaining the proper format when adding a variant: Code:
$ gsettings describe org.gnome.desktop.input-sources sources us layout ch layout, fr variant it layout in that order on the desktop with the second in the list set as the current layout. Code:
#!/bin/bash |
I didn't find any well-working solutions in 2024, so I've made one. Search for the "Shyriiwook" extension in the GNOME Shell Extensions store. The extension uses getInputSourceManager and exposes it as a D-Bus interface without relying on org.gnome.Shell.Eval. 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 and that's it:
Code:
$ gdbus introspect \ |
A modified code in post #12 has worked reliably on these systems:
Debian 12.5 GNOME 43.9 Windowing X11 4/8/16 cores CPU Code:
#!/bin/bash |
All times are GMT -5. The time now is 03:44 AM. |