Last active
June 21, 2017 15:23
-
-
Save abrahammurciano/312a75430d9fc99c5786c974d1439628 to your computer and use it in GitHub Desktop.
Automatically switches keyboard layout when USB keyboard is attached. Flowchart of process available at https://creately.com/diagram/j472uvyq1/CW4hZYa3gGMGo8tYR8Ks5bPtQ%3D. Currently set to automatically use Spanish (es) and English UK (gb) layout. You can customize it. All layouts can be found in /usr/share/X11/xkb/symbols
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
#!/bin/bash | |
kbd1=es #default keyboard layout | |
kbd2=gb #USB keyboard layout | |
while true | |
do | |
layout="$(setxkbmap -query | grep -a layout | cut -c13-14)" | |
for dev in /sys/bus/usb/devices/*-*:* | |
do | |
#If kbd is in | |
if [[ "$(cat $dev/bInterfaceClass)" == "03" && "$(cat $dev/bInterfaceProtocol)" == "01" ]] | |
then | |
#If kbs is spanish | |
if [[ $layout == $kbd1 ]] | |
then | |
setxkbmap $kbd2 | |
layout=$kbd2 | |
fi | |
#Break FOR loop and wait 5 for next iteration of WHILE loop | |
break | |
fi | |
if [[ $layout == $kbd2 ]] | |
then | |
setxkbmap $kbd1 | |
layout=$kbd1 | |
fi | |
done | |
sleep 5s | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment