42

Can I make a custom keyboard layout (one that wasn’t included with OS X by default) the system default — even for the login screen?

Mathias Bynens
  • 11,642
  • 13
  • 66
  • 111

4 Answers4

16

This works on OSX 10.9 Mavericks, with a keyboard layout that I created with Ukulele. Assuming that you have the layout already installed in your system, log into your account and make your custom keyboard layout active.

Open a terminal and run the following command:

cp /Library/Preferences/com.apple.HIToolbox.plist /tmp/

If you intend to use a text editor (e.g., TextWrangler) to make this change instead of XCode (which has a specialized graphical plist editor), also run:

plutil -convert xml1 /tmp/com.apple.HIToolbox.plist

Now, open /tmp/com.apple.HIToolbox.plist in the text editor or in XCode.

Throughout the file you will find several mentions of a KeyboardLayout ID key followed by an integer and KeyboardLayout Name followed by a string. Change these strings to the name of your custom keyboard layout and the id integers to the ID of your layout (the easiest way to find the right values is to compare with your user settings found in the file ~/Library/Preferences/com.apple.HIToolbox.plist.

Also the value of the key AppleCurrentKeyboardLayoutInputSourceID must be changed accordingly (probably to something like org.unknown.keylayout.NameOfYourLayout). Again you can find this value in your local preference file.

Once these changes are done, save the file and go back to the terminal. To play it safe, you can create a copy of the original com.apple.HIToolbox.plist file, just in case you made an error and need to roll back. For instance, to save a copy in your Documents folder:

sudo cp /Library/Preferences/com.apple.HIToolbox.plist ~/Documents

Then install your change with the following:

sudo sh -c 'cat /tmp/com.apple.HIToolbox.plist > /Library/Preferences/com.apple.HIToolbox.plist'

(It isn't necessary to convert your file back out of text form with plutil if you did so earlier.)

Exit the terminal, and restart the computer (logout is not sufficient: the file will not be reread). After restart, you should have your keyboard layout in the login screen.

NOTE: it's possible that it would have been enough to copy the file com.apple.HIToolbox.plist from ~/Library/Preferences/ to /Library/Preferences/, however in my case it has more entries, so I decided to play it safe and just modify the existing file.

Trey
  • 536
12

I found this old MacWorld tip, that suggested running the Setup Assistant again:

sudo /System/Library/CoreServices/Setup Assistant.app\
/Contents/MacOS/Setup Assistant

At first I thought this wasn’t supported in Lion anymore as running this command didn’t seem to have any effect. Only after posting this question, I noticed there’s a typo in the command. The space characters need to be escaped properly, or the location of the binary needs to be quoted. For this reason, the tip I linked to doesn’t work.

Here’s the correct command:

sudo "/System/Library/CoreServices/Setup Assistant.app/Contents/MacOS/Setup Assistant"

Alternatively, this would work as well:

sudo /System/Library/CoreServices/Setup\ Assistant.app/Contents/MacOS/Setup\ Assistant

Another gotcha that wasn’t mentioned on the page I linked to: the custom keyboard layout needs to be installed in /Library/Keyboard Layouts/ (i.e. cd /Library/Keyboard\ Layouts), not ~/Library/Keyboard Layouts, for it to appear in the Setup Assistant’s keyboard layout selection screen.


Update: As of OS X 10.8, you’ll need to run an extra command (i.e. remove a file first):

sudo rm /var/db/.AppleSetupDone; sudo "/System/Library/CoreServices/Setup Assistant.app/Contents/MacOS/Setup Assistant"

Also, you will have to create a new user account in order to complete the Setup Assistant — but don’t worry, you can delete the new account afterwards.

This trick doesn’t work anymore in recent OS X 10.8 versions.


Update: Here’s everything I know about custom keyboard layouts on OS X.

Mathias Bynens
  • 11,642
  • 13
  • 66
  • 111
  • I followed your steps for the Mountain Lion 10.8 and ran the setup assistant gain set my default keyboard layout to Dvorak and tried to login but it did not work. on reboot it was still using qwerty for the login screen. – ams Jan 05 '13 at 22:01
  • Yeah, it doesn’t seem to work anymore since OS X 10.8. :( – Mathias Bynens Nov 01 '13 at 22:21
3

I’m using a custom keyboard layout created with Ukelele in OS X 10.8.5. I changed the login screen keyboard layout with the following steps:

  1. Open Users & Groups in System Preferences
  2. Select Login Options from the bottom of the left panel
  3. Check Show Input menu in login window
  4. Go to login screen
  5. Select the preferred layout under Other input sources from the input menu, located at top right
  6. Go back and uncheck the Show Input menu in login window to prevent further changes to the login layout

I found this method far easier than editing some random .plist files and running commands it the Terminal.

This method might require administrative access, as you possibly have to unlock the right pane in step 3. above by clicking the lock icon at the bottom.

Update: Sadly, this doesn’t seem to work on OS X 10.9.

Mathias Bynens
  • 11,642
  • 13
  • 66
  • 111
Jawa
  • 2,484
  • I’ve awarded you the bounty as this seemed like the best answer, but it doesn’t actually seem to work — it always goes back to the default US keyboard layout. To test this, I’ve used a keyboard layout that allows me to type three symbols with one keystroke, so that I can see how many masked characters appear in the password input box. After applying the steps you mentioned, I could only enter one symbol at a time (as per the US keyboard). – Mathias Bynens Nov 08 '13 at 21:42
  • Can you describe what doesn't work with OS X 10.9? I am able to follow these steps (I didn't do step 6) successfully when using the Workman layout (found here: http://workman.deekayen.net/). My problem however is that if that layout is selected and I lock the computer, the input menu won't show in the login screen, whereas it's fine if I have Dvorak or something else natively supported by OS X. (i.e. I see the menu and can switch back to U.S. if needed) – Timothée Boucher Nov 11 '13 at 07:04
  • @TimothéeBoucher My previous comment describes what goes wrong, and how I tested this. – Mathias Bynens Nov 11 '13 at 13:30
2

After installing macOS Sierra my custom layout was reinitialized back to the default each time after login in my account.

Apple added new keyboards and the ID was conflicting with the keyboard I was using.

To validate if you have this issue run:

sudo touch /Library/Keyboard\ Layouts/

The output:

Keyboard Layouts: duplicate keyboard layout identifier 5000.
Keyboard Layouts: keyboard layout identifier 5000 has been replaced with 16383.

The output claims it fixes something but it actually did not do anything. I still had to edit the layout myself and it started working like before.