Last active
November 6, 2021 11:48
-
-
Save noborus/7541419 to your computer and use it in GitHub Desktop.
ibus_toggle のRuby版(iBus 1.4以下対応)
ruby-dbusが必要($ gem install ruby-dbus)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/ruby | |
# -*- coding: utf-8 -*- | |
require 'dbus' | |
IBUS_SERVICE="org.freedesktop.IBus" | |
IBUS_PATH_IBUS="/org/freedesktop/IBus" | |
IBUS_INTERFACE_IBUS="org.freedesktop.IBus" | |
IBUS_INTERFACE_INPUTCONTEXT="org.freedesktop.IBus.InputContext" | |
def get_address | |
Dir.glob(ENV['HOME'] + "/.config/ibus/bus/*").each {|file| | |
File.open(file).each_line {|line| | |
/IBUS_ADDRESS=/ =~ line | |
next if !$' | |
return $'.chop | |
} | |
} | |
end | |
ibus_bus = DBus::RemoteBus.new(get_address()) | |
ibus_service = ibus_bus.service(IBUS_SERVICE) | |
ibus = ibus_service.object(IBUS_PATH_IBUS) | |
ibus.introspect | |
ibus.default_iface = ibus[IBUS_INTERFACE_IBUS] | |
# /org/freedesktop/IBus/InputContext_* | |
ic_name = ibus.CurrentInputContext[0] | |
input_context = ibus_service.object(ic_name) | |
input_context.introspect | |
input_context.default_iface = IBUS_INTERFACE_INPUTCONTEXT | |
if input_context.IsEnabled[0] | |
input_context.Disable | |
else | |
input_context.Enable | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment