Keyboard Codes in First Run Script

Sachin_Parmar
Contributor

Hi All,

Just positing this on the off chance anyone may know or can link me a list of keyboard codes, the numerical value that I can use in my first run script, (yes I have googled it before that comes back!). For a little context here's an excerpt of the script i'm amending for setting the Australia locale:

#!/bin/sh
PLBUDDY=/usr/libexec/PlistBuddy
KEYBOARDNAME="Australian"
KEYBOARDCODE="2"
LANG="en"
REGION="en_AU"
ARD="/System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart"
SUBMIT_TO_APPLE=NO
SUBMIT_TO_APP_DEVELOPERS=NO

###############
## functions ##
###############

update_kdb_layout() {
  ${PLBUDDY} -c "Delete :AppleCurrentKeyboardLayoutInputSourceID" "${1}" &>/dev/null
  if [ ${?} -eq 0 ]
  then
    ${PLBUDDY} -c "Add :AppleCurrentKeyboardLayoutInputSourceID string com.apple.keylayout.${KEYBOARDNAME}" "${1}"
  fi

  for SOURCE in AppleDefaultAsciiInputSource AppleCurrentAsciiInputSource AppleCurrentInputSource AppleEnabledInputSources AppleSelectedInputSources
  do
    ${PLBUDDY} -c "Delete :${SOURCE}" "${1}" &>/dev/null
    if [ ${?} -eq 0 ]
    then
      ${PLBUDDY} -c "Add :${SOURCE} array" "${1}"
      ${PLBUDDY} -c "Add :${SOURCE}:0 dict" "${1}"
      ${PLBUDDY} -c "Add :${SOURCE}:0:InputSourceKind string 'Keyboard Layout'" "${1}"
      ${PLBUDDY} -c "Add :${SOURCE}:0:KeyboardLayout ID integer ${KEYBOARDCODE}" "${1}"
      ${PLBUDDY} -c "Add :${SOURCE}:0:KeyboardLayout Name string '${KEYBOARDNAME}'" "${1}"
    fi
  done
}

update_language() {
  ${PLBUDDY} -c "Delete :AppleLanguages" "${1}" &>/dev/null
  if [ ${?} -eq 0 ]
  then
    ${PLBUDDY} -c "Add :AppleLanguages array" "${1}"
    ${PLBUDDY} -c "Add :AppleLanguages:0 string '${LANG}'" "${1}"
  fi
}

update_region() {
  ${PLBUDDY} -c "Delete :AppleLocale" "${1}" &>/dev/null
  ${PLBUDDY} -c "Add :AppleLocale string ${REGION}" "${1}" &>/dev/null
  ${PLBUDDY} -c "Delete :Country" "${1}" &>/dev/null
  ${PLBUDDY} -c "Add :Country string ${REGION:3:2}" "${1}" &>/dev/null
}

Keyboard code "2" currently refers to UK - English. Any ideas?

Thanks,

Sachin

1 ACCEPTED SOLUTION

chicaked
New Contributor II

Hi Sachin, I was never able to find a full list myself but did find that when I changed the KB language manually I was then able to check the file: ~/Library/Preferences/com.apple.HIToolbox.plist for the keys needed. I'll list you the ones I needed to find below:

KEYBOARDNAME="U.S."
KEYBOARDCODE="0"

KEYBOARDNAME="Australian"
KEYBOARDCODE="15"

KEYBOARDNAME="British"
KEYBOARDCODE="2"

KEYBOARDNAME="French"
KEYBOARDCODE="1"

KEYBOARDNAME="German" KEYBOARDCODE="3"

View solution in original post

4 REPLIES 4

chicaked
New Contributor II

Hi Sachin, I was never able to find a full list myself but did find that when I changed the KB language manually I was then able to check the file: ~/Library/Preferences/com.apple.HIToolbox.plist for the keys needed. I'll list you the ones I needed to find below:

KEYBOARDNAME="U.S."
KEYBOARDCODE="0"

KEYBOARDNAME="Australian"
KEYBOARDCODE="15"

KEYBOARDNAME="British"
KEYBOARDCODE="2"

KEYBOARDNAME="French"
KEYBOARDCODE="1"

KEYBOARDNAME="German" KEYBOARDCODE="3"

Sachin_Parmar
Contributor

@chicaked Amazing, thank you I will give these a test, surprising these codes are not documented anywhere. Thanks

bentoms
Release Candidate Programs Tester

@Sachin_Parmar & @chicaked I've been working on something, it's very work in progress... BUT, if you run: this gist & feed it in a countries ISO code then is should output something like:

Enter A Country ISO Code: gb

Country: United Kingdom

Timezones: ['Europe/London']

Locales: [u'cy_GB', u'en_GB', u'gd_GB', u'kw_GB']

Languages: {u'gd': u'Scottish Gaelic', u'cy': u'Welsh', u'en': u'English', u'kw': u'Cornish'}

KB Layouts: [(u'-790', (u'Welsh', u'com.apple.keylayout.Welsh')), (u'29', (u'Canadian English', u'com.apple.keylayout.CanadianEnglish'))]

I have plans for it, hence it being WIP.. but hope it helps.

bentoms
Release Candidate Programs Tester

well WIP is WIP, just realised things changed with 10.11.

On 10.10 I get:

Enter A Country ISO Code: gb

Country: United Kingdom

Timezones: ['Europe/London']

Locales: [u'cy_GB', u'en_GB', u'kw_GB']

Languages: {u'cy': u'Welsh', u'en': u'English', u'kw': u'Cornish'}

KB Layouts: [(u'-500', (u'Irish Extended', u'com.apple.keylayout.IrishExtended')), (u'-790', (u'Welsh', u'com.apple.keylayout.Welsh')), (u'12825', (u'Colemak', u'com.apple.keylayout.Colemak')), (u'16300', (u'Dvorak', u'com.apple.keylayout.Dvorak')), (u'16301', (u'Dvorak - Qwerty u2318', u'com.apple.keylayout.Dvorak-Qwertyu2318')), (u'16302', (u'Dvorak - Left', u'com.apple.keylayout.Dvorak-Left')), (u'16303', (u'Dvorak - Right', u'com.apple.keylayout.Dvorak-Right')), (u'2', (u'British', u'com.apple.keylayout.British')), (u'250', (u'British - PC', u'com.apple.keylayout.British-PC')), (u'29', (u'Canadian English', u'com.apple.keylayout.CanadianEnglish')), (u'50', (u'Irish', u'com.apple.keylayout.Irish'))]