What macOS doesn't document about keyboard layouts
Latam-Keyboard had issues open since 2019. Fixing them, almost every one turned out to have a cause Apple doesn't document: IDs reassigned silently, a language Word doesn't recognize, icons that disappear. Here's what I found, and how I tested it without a Latin American keyboard.
In 2017 I published Latam-Keyboard, a set of keyboard layouts for using Latin American keyboards on macOS. Apple’s own Latin American layout doesn’t match many of those keyboards: on external ones, for example, < and > often end up on the wrong key.
In late November 2026 the repository had four open issues and three more that had been closed without a fix, the oldest from 2019. Over one week, twelve versions went out, and every issue ended up fixed or closed with the right reason. The interesting part wasn’t the number: almost every bug had a cause that isn’t in any Apple documentation. This post collects them, along with how I ended up testing everything without a Latin American keyboard.
What a keyboard layout is on macOS
A .keylayout file is XML. It defines several key maps, one per modifier combination (none, Shift, Caps Lock, Option, Command, Control), and each map says which character each key code types:
<keyMap index="0">
<key code="41" output="ñ"/>
<key code="33" action="a8"/> <!-- accent key: waits for the next letter -->
...
</keyMap>
Accents are small state machines (<actions> and <terminators>): ´ types nothing, changes state, and the next a comes out as á. A loose .keylayout goes into ~/Library/Keyboard Layouts and macOS reads it. It can also be packaged in a bundle with an Info.plist, and that turned out to matter.
1. Duplicate IDs are reassigned silently
Each layout has a numeric id on its <keyboard> tag. All six layouts in the project had the same one: 5006. Nobody had noticed, because macOS doesn’t complain. It only logs it when it rebuilds its cache:
Keyboard Layouts: duplicate keyboard layout identifier 5006.
Keyboard Layouts: keyboard layout identifier 5006 has been replaced with 16383.
Keyboard Layouts: duplicate keyboard layout identifier 5006.
Keyboard Layouts: keyboard layout identifier 5006 has been replaced with 16382.
...
It makes up an ID for five of the six, and which one gets which depends on the order it loads them, which can change after a macOS update. That fits a 2024 issue: after updating to Sonoma, a layout showed up grayed out, as if it were already added, and reinstalling didn’t help. The fix was to give each layout its own negative ID in the Unicode group (group="126"), which is what Ukelele does.
2. A layout’s ID changes after its name is read
To declare a language (point 3), I moved the layouts into a bundle. In the Info.plist, each layout has an entry with its TISInputSourceID, and I gave them clean IDs like …latam.Latam-B.
Testing it through the input source API (TIS), the same layout returned two different IDs. macOS first reports an automatic ID, <bundle id>.keylayout.<name without spaces>, and only switches to the Info.plist’s ID after something reads the layout’s name. If the two differ, the same layout has two identities, and macOS saves the input sources you added by ID.
I found out because my own test fell into it: it enabled a layout by one ID, read its name to print it, and then couldn’t find it to disable it. The rule became: the plist’s TISInputSourceID has to be exactly the automatic one, for example …latam.keylayout.LatinAmerican-B.
3. Word doesn’t recognize es-419
The oldest issue, from 2019, said that typing an accented word in Word switched spell checking to English. Word picks the text’s language from the active layout’s language, and a loose .keylayout has no place to declare one.
With the bundle, I declared it as es-419, the code for Latin American Spanish, and macOS accepted it. But I didn’t know whether it worked until I tested it in Word. You can ask Word through AppleScript which language each word has:
tell application "Microsoft Word"
get language ID of word 2 of active document
end tell
With es-419, Word 16.115 returned language none for every word: not Spanish, not English, no language at all. With Apple’s Latin American layout, the same sentence came out with a language. I changed the code to es, which is what Apple’s layout declares, and the same line became spanish, accents included. My first fix was going in the right direction, but with a code Word doesn’t understand.
4. With Command held, the layout turned back into US
Three issues (#6, #10, #11) described the same thing in different ways: Cmd++ didn’t zoom in the browser, and Cmd+? zoomed out. In 2023 someone saw it in Keyboard Viewer: when holding Command, the keys switched to those of a US keyboard.
The Command map (index 6) was a copy of the US layout, so the + key sent ] and - was on the '/? key. Apple’s layouts keep their own characters with Command. The fix was to rebuild that map from the map without modifiers, replacing each accent key with the character it types on its own, so Cmd+´ works as a shortcut instead of waiting for a letter.
5. Caps Lock, the map everyone forgets
Caps Lock has its own map, and two bugs lived there for years:
- Lowercase
ñ(#8): Shift+ñgaveÑ, but with Caps Lock on it still typedñ. <and|swapped. In 2020, a pull request swapped those two keys for Type B, but only in the maps without modifiers and with Shift. The Caps Lock map kept the old arrangement: with Caps Lock on, the<key typed|.
The second one wasn’t found by reading the code: it showed up in a Keyboard Viewer screenshot with Caps Lock on. Since then, the rule is that any key swap applies to every map, and the automated test checks those two keys without modifiers, with Shift and with Caps Lock.
6. Liquid Glass and template icons
Since macOS 26, the menu bar is transparent, and its icons are tinted white or black depending on the wallpaper, not on light or dark mode. A fixed black icon disappears over a dark wallpaper, and a fixed white one over a light wallpaper. The project had “White” versions with a white icon since 2020 (#3), meant for dark mode, and with Liquid Glass neither one was always right.
The obvious fix is a template icon, which macOS recolors itself. For keyboard layouts it’s turned on with an Info.plist key that isn’t in the public documentation: TISIconIsTemplate. It worked in the menu bar. But in the badge that appears next to the cursor when you switch layouts, macOS draws the template icon in the same blue as the badge’s background, and the selected layout looks empty. Another project, EurKEY Next, documents the same bug on Sonoma and Sequoia, and it still happens on macOS 27.
I ended up with a fixed icon: the black silhouette of the continent with a thin white outline. It shows over light and dark wallpapers, and in the badge. The outline is computed separately for each size in the .icns, so it doesn’t swallow the silhouette at 16 px. With that, the White versions no longer made sense and were removed.
How to test a layout without the keyboard
Testing these changes the traditional way means installing, logging out, logging back in, and typing on a Latin American keyboard, which I didn’t have at hand. But macOS can tell you what each key types. The input source API returns the layout’s data, and UCKeyTranslate simulates the key press:
UCKeyTranslate(layout, keyCode, UInt16(kUCKeyActionDown), modifiers,
UInt32(LMGetKbdType()), 0, &deadKeyState, 4, &length, &chars)
With that, the project’s test installs the bundle in the user’s folder and checks, for each layout, that it loads, that its ID doesn’t change, that its language is Spanish, and what keys type: ñ with Caps Lock, accents, Command shortcuts, the < and | keys with each modifier, and that all 95 printable ASCII characters can be typed. Before each fix, the test failed exactly on the new check.
Getting there meant avoiding three traps, none of them documented:
- macOS only provides a bundled layout’s key data while the layout is enabled. The test enables each one for a moment and disables it again, without touching the layout in use.
- macOS caches the layouts it finds. If you don’t delete
com.apple.IntlDataCache.le*from the user’s cache folder, you’re testing the old files. And the first query after deleting it can come back incomplete while the cache rebuilds. - Asking for the list of input sources without a filter leaves out bundled layouts, and also gives different results between calls. Always filter by the “keyboard layout” type.
What only shows on screen
The automated test can’t see icons, and it doesn’t know which language Word decides on. Two of the bugs, the Caps Lock one and the empty badge, showed up in screenshots, not in the code. And the Word fix was only confirmed by asking Word. Keyboard Viewer with each modifier, the icon over two wallpapers and the badge next to the cursor all had to be checked by eye.
One Keyboard Viewer detail that’s confusing: the orange outline on the ´ key isn’t a stuck key. It marks an accent key.
The community, in the forks too
The project has 62 forks. I reviewed all of them with the GitHub API, comparing each branch with mine, and only three had their own changes. Two contributed ideas that made it into the project. One solved | on keyboards without a key between the left Shift key and Z, like a MacBook with a US keyboard; it’s now on Option + the key below Esc. The other brought a security audit of the files and the experience of someone for whom the “built-in keyboard” layout worked with an external keyboard. That became a README section on what gets installed and a concrete test for choosing a type: press the key between the left Shift key and Z, and if it doesn’t type <, switch types.
The README now thanks the 19 people who reported, investigated, sent pull requests or shared their versions, and the release notes for version 1.3.0 mention each of them. Several issues were, underneath, solved by the reports themselves: someone had found the cause in 2023, and it just needed someone to fix it.
To install it
brew install --cask neosergio/tap/latam-keyboard
After installing, log out, log back in, and add the layout in System Settings > Keyboard > Input Sources. It’s listed under Spanish. The code, the test and the release notes are on GitHub.
Comments