How to Change Keyboard Layouts (Ubuntu 24.04 Wayland)

November 30, 2025 note-to-self

I have my wierd Ubuntu laptop keyboard mapped the way I want it, and bought a new bluetooth, ergonomic, portable keyboard whose mappings are also weird and hosed.

I couldn't get them to play together, so I use this script to swap between them. It's better than putting up with it, or messing endlessly with gsettings or keyd.

Put it in ~/bin/keyboard and run it with ~/bin/keyboard [show|laptop|ext]

#!/usr/bin/env bash

# keyboard: switch between laptop and external keyboard key mappings

LAPTOP_OPTS="['ctrl:nocaps', 'ctrl:swap_lalt_lctl', 'ctrl:swap_ralt_rctl', 'caps:ctrl_modifier']"
EXTERNAL_OPTS="['caps:ctrl_modifier', 'ctrl:swap_lwin_lctl']"

case "$1" in
  laptop)
    echo "➡ Switching to laptop keyboard mappings"
    gsettings set org.gnome.desktop.input-sources xkb-options "$LAPTOP_OPTS"
    ;;
  ext|external)
    echo "➡ Switching to external keyboard mappings"
    gsettings set org.gnome.desktop.input-sources xkb-options "$EXTERNAL_OPTS"
    ;;
  show)
    echo "Current mapping:"
    gsettings get org.gnome.desktop.input-sources xkb-options
    ;;
  *)
    echo "Usage: keyboard {laptop|ext|show}"
    exit 1
    ;;
esac
Most posts are for my own reference and reflection, and shouldn’t be taken as fully accurate or instructional.