Skip to content

Instantly share code, notes, and snippets.

@koyudoon
Created December 9, 2011 19:49
Show Gist options
  • Save koyudoon/1453003 to your computer and use it in GitHub Desktop.
Save koyudoon/1453003 to your computer and use it in GitHub Desktop.
IBus enable/disable
#! /usr/bin/python
# coding: utf-8
import sys
try:
from ibus import bus, inputcontext
except ImportError:
sys.exit(1)
msg_usage = '''usage: ibus-switch.py [on | off | toggle]
on : enable input method
off : disable input method
toggle : toggle input method
-h, --help: display this help and exit
'''
if (not len(sys.argv) is 2 or
sys.argv[1].lower() in ['-h', '--help']):
print msg_usage
sys.exit(1)
arg_switch = sys.argv[1].lower()
try:
bus = bus.Bus()
ic = inputcontext.InputContext(bus, bus.current_input_contxt())
if arg_switch == 'toggle':
if ic.is_enabled():
arg_switch = 'off'
else:
arg_switch = 'on'
if arg_switch == 'on':
ic.enable()
elif arg_switch == 'off':
ic.disable()
except:
import subprocess
subprocess.call(['/usr/bin/ibus-daemon', '-drx'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment