3

I have two commands those are binded with CapsLock key and Shift+CapsLock as mentioned in this Q&A Modeless/stateless layout language switching with Caps Lock, again (18.04 LTS Bionic Beaver)

My requirement is to toggle the languages with Super+Space without graphical representation on screen.

enter image description here

I have disabled the default shortcuts for switch to next input source and previous input source.

enter image description here

now I can bind any command to Super+Space like below

enter image description here

Thoughts:

It is possible to give these two commands as two shortcuts for example:

Super+Space for English
Shift+Super+Space for Ukranian

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()"

When the value is 1 in "inputSource[ ]" the language changes to Ukranian and if it is 0 language changes to English

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()"

Question:

I am looking for a command that can read the present value and change to other value among 0 and 1 in the below command so that I can toggle the languages without the need of Shift+Super+Space

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()"
PRATAP
  • 22,460
  • 1
  • @danzel can you post the script as answer.. credit goes to you.. – PRATAP Apr 17 '19 at 14:25
  • 1
    that's not my script. I googled "imports.ui.status.keyboard.getInputSourceManager" looking for some documentation, and the git repo was the first result. I actually don't use gnome so I cannot test it. Feel free to post it yourself if it works. – danzel Apr 17 '19 at 14:55

3 Answers3

2

With the help of @danzel, the link provided by him..https://github.com/Nekotekina/kbhook/blob/master/layout_rotate.sh

I have saved the below script as ~/SL.sh and created a shortcut with Super+Space as
/bin/bash /home/pratap/SL.sh

enter image description here

#!/bin/bash

CURRENT=`gdbus call --session --dest org.gnome.Shell --object-path /org/gnome/Shell --method org.gnome.Shell.Eval "imports.ui.status.keyboard.getInputSourceManager().currentSource.index"`

if [ "$CURRENT" == "(true, '1')" ]; then
  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()"
else
  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()"
fi

now Super+Space is toggling the Languages without graphical representation which I was looking for..

enter image description here

thanks to @danzel once again

PRATAP
  • 22,460
1

The Quick Lang Switch Gnome-shell extension does exactly that, and switching languages happens instantaneously. Plus, it fixes any focus stealing issues with current window while it does not require a custom-shortcut (the regular one changes behavior), so gnome-tweak-tool choices still work.

Disclaimer: I am the developer of the Quick Lang Switch...

andrew.46
  • 38,003
  • 27
  • 156
  • 232
ankostis
  • 235
  • 2
  • 11
1

If you just want to assign a unique shortcut for every input method you have (e.g. Super + Space + 1 for US, Super + Space + 2 for UK, etc), I would recommend another GNOME Shell Extension: Shyriiwook. It supports old (pre 45) and newer GNOMEs (45+). It's super simple and minimalist, it doesn't even have a GUI. After installing it, a new D-Bus interface will be exposed in your GNOME Shell Session, and you'll be able to manage input methods programmatically.

Examples with CLI (gdbus).

Query current configuration with:

$ 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']; readonly s currentLayout = 'us'; }; };

Select input method by their ID with:

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

This allows to use it in scripts and custom shortcuts very easily.

Disclaimer: I am the developer of this extension.

madhead
  • 702
  • 3
  • 10