A robust, user-level script to automatically switch your GNOME keyboard layout when specific Bluetooth keyboards connect or disconnect.
- Multi-Device Support: Configure multiple devices with different layouts (e.g., Mac layout for MX Keys, generic for others).
- Priority System: If multiple devices are configured, the first one found connected takes priority.
- Config Separation: User configuration is stored in
~/.config/layout-autoswitch/config– safe from script updates. - User-Level Service: Runs entirely as your user—no root/sudo required.
- Desktop Notifications: Get a notification whenever the layout changes.
- GNOME Desktop Environment (uses
gsettings). - BlueZ (provides
bluetoothctl). - libnotify-bin (provides
notify-sendfor strong descriptors).
Run the provided installer to set up the directories and systemd service automatically:
chmod +x install.sh
./install.sh- Edit the configuration file created at
~/.config/layout-autoswitch/config. - Find your device MAC address using
bluetoothctl devices. - Add your devices to the
DEVICESarray.
Example ~/.config/layout-autoswitch/config:
# Format: "MAC_ADDRESS:DEVICE_NAME:LAYOUT_ID"
DEVICES=(
"D2:5E:40:00:B8:28:MX Keys Mini:fr+mac"
"AA:BB:CC:DD:EE:FF:Generic Keyboard:us"
)
# Fallback layout when no known devices are connected
DEFAULT_LAYOUT="fr"Check the service status:
systemctl --user status layout-autoswitch.serviceRead real-time logs:
journalctl --user -u layout-autoswitch -fThe script runs in the background and checks (polls) for connected devices every 5 seconds.
- It loops through your
DEVICESlist in order. - If it finds a connected device, it switches to that device's specified layout.
- If no listed devices are connected, it switches to
DEFAULT_LAYOUT. - It only applies changes (and notifies you) if the state actually changes.
systemctl --user disable --now layout-autoswitch.service
rm ~/.config/systemd/user/layout-autoswitch.service
rm -rf ~/.config/layout-autoswitch