Skip to content

Instantly share code, notes, and snippets.

@ondt
Last active April 20, 2020 00:23
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 ondt/54c3455975f1335b4298cfb591ed3cdf to your computer and use it in GitHub Desktop.
Save ondt/54c3455975f1335b4298cfb591ed3cdf to your computer and use it in GitHub Desktop.
A script that switches keyboard layouts automatically based on the X window title
#!/bin/bash
# for xtitle to work properly
sleep 0.5
layout="us"
xtitle -s -f '%s\n' | while read window_title; do
case $window_title in
"Messenger"* | "Slack"*)
if [[ "$layout" != "cz" ]]; then
echo "Changing keyboard layout to CZ"
setxkbmap cz -variant qwerty
layout="cz"
fi
;;
*)
if [[ "$layout" != "us" ]]; then
echo "Changing keyboard layout to US"
setxkbmap us
layout="us"
fi
;;
esac
done
@ondt
Copy link
Author

ondt commented Apr 19, 2020

dependency: https://github.com/baskerville/xtitle

git clone --depth 1 https://github.com/baskerville/xtitle.git
cd xtitle/
make && sudo make install

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment