Last active
August 29, 2015 13:56
-
-
Save Visgean/9158551 to your computer and use it in GitHub Desktop.
switches from and to apple keyboard (apple keyboard has ctrl,alt,meta layout and I want to have ctrl, meta, alt layout)
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/env python | |
# This script switches from and to apple keyboard (apple keyboard has ctrl,alt,meta layout and I want to have ctrl, meta, alt layout) | |
import subprocess | |
from gi.repository import Gio | |
SWITCH_ALT_WIN = 'altwin:swap_lalt_lwin' # kxb option to switch left win and alt, have a look in /usr/share/X11/xkb/rules/base.lst | |
gsettings = Gio.Settings.new('org.gnome.desktop.input-sources') | |
current_settings = gsettings['xkb-options'] | |
# check if the Aluminium Keyboard is connected: | |
keyboard_present = 'Apple, Inc. Aluminium Keyboard' in subprocess.check_output('lsusb') | |
if SWITCH_ALT_WIN in current_settings and not keyboard_present: | |
current_settings.remove(SWITCH_ALT_WIN) | |
elif keyboard_present: | |
current_settings.append(SWITCH_ALT_WIN) | |
gsettings['xkb-options'] = current_settings | |
gsettings.apply() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment