Skip to content

Instantly share code, notes, and snippets.

@Visgean
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Visgean/9158551 to your computer and use it in GitHub Desktop.
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)
#!/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