Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save cympfh/1dafa0e1347f2607c42ad900782c994d to your computer and use it in GitHub Desktop.

Select an option

Save cympfh/1dafa0e1347f2607c42ad900782c994d to your computer and use it in GitHub Desktop.
#!/bin/bash
BUILTIN_KBD_NAME="AT Translated Set 2 keyboard"
BLUETOOTH_KBD_NAME="HHKB-Hybrid_"
xinput set-prop "$BUILTIN_KBD_NAME" "Device Enabled" 1
trap "xinput set-prop '$BUILTIN_KBD_NAME' 'Device Enabled' 1; exit" 2
STATUS=none
while :; do
if bluetoothctl info | grep "$BLUETOOTH_KBD_NAME" >/dev/null; then
NEW_STATUS=1 # BT kbd is available
else
NEW_STATUS=0
fi
if [ "$STATUS" != "$NEW_STATUS" ]; then
STATUS="$NEW_STATUS"
if [ "$STATUS" = 1 ]; then
echo "BT kbd is available. Disable the builtin kbd"
xinput set-prop "$BUILTIN_KBD_NAME" "Device Enabled" 0
else
echo "BT kbd is not available. Enable the builtin kbd"
xinput set-prop "$BUILTIN_KBD_NAME" "Device Enabled" 1
fi
fi
sleep 1
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment