Monday, October 25, 2010

Change default keyboard layout for loginwindow

We discovered that a system restore image we used to deploy new Macs with had the wrong keyboard layout at the loginwindow. If you change the keyboard layout in the Accounts PrefPane, it just affects the currently logged in user.
Apples solution to this is either to reinstall Mac OS X or select to show the input menu in the loginwindow, this is two solutions that I can't accept, so I started digging and found a solution!

The settings are stored in /Library/Preferences/com.apple.HIToolbox.plist and changing these solved my problem.

Here is quick and dirty script to change the default keyboard layout to Swedish:


#!/bin/bash

# This will set default keyboard language to Swedish.

# Path to plist file
PLISTDOMAIN="/Library/Preferences/com.apple.HIToolbox.plist"

# Path to PlistBuddy
PB="/usr/libexec/PlistBuddy"

"$PB" -c "set :AppleDefaultAsciiInputSource:KeyboardLayout\ ID 7" "$PLISTDOMAIN"
"$PB" -c "set :AppleDefaultAsciiInputSource:KeyboardLayout\ Name Swedish\ -\ Pro" "$PLISTDOMAIN"
"$PB" -c "set :AppleCurrentKeyboardLayoutInputSourceID com.apple.keylayout.Swedish-Pro" "$PLISTDOMAIN"
"$PB" -c "set :AppleEnabledInputSources:0:KeyboardLayout\ ID 7" "$PLISTDOMAIN"
"$PB" -c "set :AppleEnabledInputSources:0:KeyboardLayout\ Name Swedish\ -\ Pro" "$PLISTDOMAIN"

exit 0

No comments: