Skip to content

Instantly share code, notes, and snippets.

@Ajnasz
Last active August 25, 2017 08:50
Show Gist options
  • Save Ajnasz/616bf8873d0255686bbe2245a85a639d to your computer and use it in GitHub Desktop.
Save Ajnasz/616bf8873d0255686bbe2245a85a639d to your computer and use it in GitHub Desktop.
#!/bin/sh
set -e
PID_FILE="/tmp/toggle_keyboard_layout.pid"
while [ -f $PID_FILE ];do
exit 0;
done;
echo $$ > $PID_FILE
PRIMARY_LAYOUT_NAME="us"
SECONDARY_LAYOUT_NAME="hu"
CURRENT_LAYOUT=`/usr/bin/setxkbmap -query | awk '/layout/ { print $2 }'`
if [ "$CURRENT_LAYOUT" = "$PRIMARY_LAYOUT_NAME" ];then
NEW_LAYOUT="$SECONDARY_LAYOUT_NAME"
else
NEW_LAYOUT="$PRIMARY_LAYOUT_NAME"
fi
/usr/bin/setxkbmap -layout $NEW_LAYOUT
notify-send -t 100 -a "toggle_keyboard_layout.sh" -u low "Keyboard layout `echo $NEW_LAYOUT | tr '[:lower:]' '[:upper:]'`"
# echo Keyboard layout $NEW_LAYOUT | osd_cat -f "-*-terminus-*-*-*-*-32-*-*-*-*-*-*-*" -c green -o 20 -i 20 -d 1 -s 2
rm $PID_FILE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment