From 9464388e078d4641b720fb695a19518f86692a5b Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Wed, 8 Nov 2023 19:56:53 +0100 Subject: keyboard_layout_select: Add shortcuts to select keyboard layout I had to upgrade to Mac OS 14 Sonoma, which in addition to adding a useless software Caps Lock indicator, also royally screwed up the way that changing keyboard layouts used to work (it worked perfectly fine). I decided to make a unique keyboard shortcut to switch to each keyboard layout to put some order to the madness. --- keyboard_layout_select.lua | 48 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 keyboard_layout_select.lua (limited to 'keyboard_layout_select.lua') diff --git a/keyboard_layout_select.lua b/keyboard_layout_select.lua new file mode 100644 index 0000000..e87f5d7 --- /dev/null +++ b/keyboard_layout_select.lua @@ -0,0 +1,48 @@ +-- Copyright (c) 2023 Teddy Wing +-- +-- This program is free software: you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation, either version 3 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program. If not, see . + + +-- Shortcuts to change keyboard layouts. +-- +-- Mac OS 14 Sonoma so completely borked switching keyboard layouts that this +-- became a necessity. Since Mac OS 14, pressing Control-Space inconceivably no +-- longer reorders the list of keyboard layouts based on the most recently used +-- layout, meaning you can no longer press Control-Space-Space to go to the +-- one-indexed third layout, then press Control-Space to go back to the +-- previous layout. Instead, the Control-Space in the second step brings you to +-- a completely different layout. Yet another hostile change by Apple to make +-- Mac OS unusable. + + +local layouts = { + "U.S.", + "French – Numerical", + "QWAZERTY2", + "Dvorak" +}; + +keyboard_layout_select_bindings = {} + +for i = 1, #layouts do + local key = tostring(i) + + keyboard_layout_select_bindings[i] = hs.hotkey.bind( + {"ctrl", "alt"}, + key, + function() + hs.keycodes.setLayout(layouts[i]) + end + ) +end -- cgit v1.2.3