Ubuntu – Manipulate the Default Shortcut Super+Space for Switching to Next Input Source without Graphical Representation

command lineshortcut-keys

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

Best Answer

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