2

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
  • 21,989
  • 8
  • 59
  • 121
  • See [this git](https://github.com/Nekotekina/kbhook/blob/master/layout_rotate.sh). – danzel Apr 17 '19 at 13:46
  • @danzel can you post the script as answer.. credit goes to you.. – PRATAP Apr 17 '19 at 14:25
  • 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

2 Answers2

1

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
  • 21,989
  • 8
  • 59
  • 121
  • Unfortunately calling dbus `org.gnome.Shell.Eval` method no longer works, ie since Gnome-shell v41, for [security reasons](https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/3943). – ankostis Jul 29 '23 at 22:23
0

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
  • 37,085
  • 25
  • 149
  • 228
ankostis
  • 181
  • 11