10

Can I set up keyboard shortcuts for each input language? For example I want to set "Ctrl + 8" for English, "Ctrl + 9" for Ukrainian and "Ctrl + 0" for Russian languages. I don't want to switch and search language I need. It takes time. I want directly to turn language I want. I had this ability in Windows. Maybe I need to install some plugin?

5 Answers5

8

Go to System Settings - Keyboard - Shortcuts. Click on "Add" button.

(See here for how to create a custom shortcut: http://web.archive.org/web/20150705203244/http://bigknol.com/create-custom-keyboard-shortcuts-in-ubuntu-for-launching-chrome-firefox/)

enter image description here

For the name write,for example name of the input language - "English".

For the command write

gsettings set org.gnome.desktop.input-sources current 0

Here 0 indicates the number of the input language. (0 for the first one, 1 for the second one, etc.)

Then press on create a shortcut button and press the key combination you want.

Change the number according to the order of input languages. For example write

gsettings set org.gnome.desktop.input-sources current 1

for creating a shortcut for the second language.

Muzaffar
  • 5,597
5

As far as current is deprecated for org.gnome.desktop.input-sources in GNOME 3.2 so for Ubuntu 18.04, you can use one of the following commands:

  1. For the first language:

    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()"
    
  2. For the second language:

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

Since Ubuntu 22.04 GNOME no longer allows the use of input-sources or accepts Eval() natively so you have to use the following workaround.

  1. Install GNOME extension Eval-GJS - This extension provides unrestricted Eval() dbus method for running arbitrary code in the compositor.
https://github.com/ramottamado/eval-gjs.git
cd eval-gjs
make install
  1. Install gnome-shell-extension-manager
sudo apt install gnome-shell-extension-manager
  1. Logout and re-login

  2. Launch gnome-shell-extension-manager and enable Eval-GJS

  3. Go to Settings -> Keyboard -> Keyboard Shortcuts and add a custom shortcut with the following command:

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

Replace the index in inputSources[0] with the actual index of the input method you wish to change to. First layout will be inputSources[0], second layout will be inputSources[1] and so on.

manatails
  • 19
  • 2
  • And since Ubuntu 23.04 Eval-GJS "is incompatible with the current GNOME version" :( – fetsh Mar 21 '23 at 12:50
  • Ok, Eval-GJS have to up the version in manifest, to make it work with current GNOME, but for now this should work: https://github.com/fetsh-edu/eval-gjs/commit/f7ef9d363f59d7578d423081d0e393c1a4096374 – fetsh Mar 21 '23 at 16:52
1

Install GNOME extension inputmethod-shortcuts and configure it.

0

I find ironic how answers under this question summarize the long history of modeless (stateless) layout switching in Ubuntu and its complicated fate.

  • The setxkbmap doesn't play nice with the GNOME Shell. It doesn't update the UI indicator and it breaks the usual configured layout switching shortcut.
  • The gsettings set org.gnome.desktop.input-sources current is deprecated and doesn't work anymore
  • The gdbus call … org.gnome.Shell.Eval … is also deprecated due to security implications.
  • There is a replacement for the Eval: ramottamado/eval-gjs, but it doesn't solve the security issue. In fact, it introduces them! A quote from their README:

The extension at https://extensions.gnome.org/extension/XXXX/eval-gjs/ was not uploaded nor maintained by me. Please refrain from installing this extension at all.


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', 'uk', 'ru']; readonly s currentLayout = 'uk'; }; };

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

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". You could have one per every language you want.

madhead
  • 702
  • 3
  • 10