gdbus call
(src)查询gnome-shell的JS接口,可以实现这一功能。#!/usr/bin/env bash
cur_idx=$(
gdbus call \
--session \
--dest org.gnome.Shell \
--object-path /org/gnome/Shell \
--method org.gnome.Shell.Eval \
"imports
.ui.status
.keyboard
.getInputSourceManager()
.currentSource
.index" |
cut -d"'" -f2
)
next_idx=$(( 1 - $cur_idx ))
gdbus call \
--session \
--dest org.gnome.Shell \
--object-path /org/gnome/Shell \
--method org.gnome.Shell.Eval \
"imports
.ui
.status
.keyboard
.getInputSourceManager()
.inputSources[$next_idx]
.activate()" \
&> /dev/null
chmod a+x
命令给脚本赋予执行权限,并且你可以将其绑定到自定义快捷键上: