Skip to main content
Question

Setting keyboard layout


Forum|alt.badge.img+15
  • Valued Contributor
  • 78 replies

Happy Friday,

I want to set the keyboard layout to Swiss German, and have tried the following things (without success):

  1. Created a .dmg of /Library/Preferences/com.apple.HIToolbox.plist (policy FUT/FEU)

  2. Created a Configuration Profile with Custom Settings from an uploaded .plist with all the proper settings.

We have a 'refresh' script that wipes student data on logout and repopulates from the user template. Neither step above changes the keyboard layout for the users. What am I missing? I know that there is a user level setting in ~/Library/ByHost, but shouldn't the User Template trump that?

Thanks!

-tep

9 replies

Forum|alt.badge.img+3

Excerpted from

https://github.com/hjuutilainen/dotfiles/blob/master/bin/osx-system-defaults.sh

defaults write /Library/Preferences/com.apple.HIToolbox AppleCurrentKeyboardLayoutInputSourceID "com.apple.keylayout.SwissGerman"
defaults write /Library/Preferences/com.apple.HIToolbox AppleDefaultAsciiInputSource -dict InputSourceKind "Keyboard Layout" "KeyboardLayout ID" -int 19 "KeyboardLayout Name" SwissGerman

Delete the default layouts (US)

defaults delete /Library/Preferences/com.apple.HIToolbox AppleEnabledInputSources

Enable SwissGerman layout

defaults write /Library/Preferences/com.apple.HIToolbox AppleEnabledInputSources -array '{ InputSourceKind = "Keyboard Layout"; "KeyboardLayout ID" = 19; "KeyboardLayout Name" = SwissGerman; }'
defaults write /Library/Preferences/com.apple.HIToolbox AppleInputSourceHistory -array '{ InputSourceKind = "Keyboard Layout"; "KeyboardLayout ID" = 19; "KeyboardLayout Name" = SwissGerman; }'
defaults write /Library/Preferences/com.apple.HIToolbox AppleSelectedInputSources -array '{ InputSourceKind = "Keyboard Layout"; "KeyboardLayout ID" = 19; "KeyboardLayout Name" = SwissGerman; }'


Forum|alt.badge.img+15
  • Author
  • Valued Contributor
  • 78 replies
  • April 24, 2015

@darrell.rennie Thanks for the response. That's the exact same verbiage that I used in my Configuration Profile :-)

I've added this to my Standards script, and will play around with it.


davidacland
Forum|alt.badge.img+18
  • Valued Contributor
  • 1811 replies
  • April 24, 2015

Hi, if its of use I've blogged our keyboard layout setting code in this article:

http://www.amsys.co.uk/2015/blog/creating-first-boot-script/#.VTqcoc57Urk

and details of a config profile (as an alternative) here:

http://www.amsys.co.uk/2015/blog/creating-config-profiles-instead-first-boot-script/#.VTqc3857Urk


tobiaslinder
Forum|alt.badge.img+16
  • Valued Contributor
  • 101 replies
  • September 3, 2015

Hi guys
Why are you setting this on the system level and not on the user level? As far as I understand every user has his own keyboard settings in

~/Library/Preferences/com.apple.HIToolbox.plist

How are the two different com.apple.HIToolbox.plist influencing each other?


Forum|alt.badge.img+15
  • Author
  • Valued Contributor
  • 78 replies
  • September 3, 2015

Hi @tobiaslinder!

You are correct: ~/Library/Preferences/com.apple.HIToolbox.plist is the ticket. My question had more to do with setting the pref universally, but I think I ended up populating the default user template.


tobiaslinder
Forum|alt.badge.img+16
  • Valued Contributor
  • 101 replies
  • September 3, 2015

Hey @tep That’s why I was asking. In our standards script the path was really set to

/Libary/Preferences/com.apple.HIToolbox.plist

which doesn’t make any sense to me.


Forum|alt.badge.img+8
  • Contributor
  • 29 replies
  • February 2, 2017

I have a similar issue.

We typically have both Canadian English and Canadian French as the 2 "enabled" keyboard layouts.

I'm trying to come up with a script that will change the keyboard back to Cdn. English on logout (if the student has changed it to Canadian French during their session). I'm having a heck of a time trying to figure it out.

At this point I'm pretty much overwriting the entire plist with my script, but it still doesn't seem be working.

Here's what I've got:

#!/bin/sh

u=student

    # set the "current" keyboard layout
    defaults write "/Users/$u/Library/Preferences/"com.apple.HIToolbox AppleCurrentKeyboardLayoutInputSourceID com.apple.keylayout.Canadian

    # set the default keyboard
    defaults write "/Users/$u/Library/Preferences/"com.apple.HIToolbox AppleDefaultAsciiInputSource
     -dict InputSourceKind "Keyboard Layout" "KeyboardLayout ID" -int 29 "KeyboardLayout Name" Canadian

    # set the "selected" Input Source
    defaults write "/Users/$u/Library/Preferences/"com.apple.HIToolbox AppleSelectedInputSources -array
     '<dict><key>InputSourceKind</key><string>Keyboard Layout</string><key>KeyboardLayout ID</key><integer>29</integer><key>KeyboardLayout Name</key><string>Canadian</string></dict>'

    # set enabled keyboards (Canadian English & Canadian French)
    defaults write "/Users/$u/Library/Preferences/"com.apple.HIToolbox AppleEnabledInputSources -array
     '<dict><key>InputSourceKind</key><string>Keyboard Layout</string><key>KeyboardLayout ID</key><integer>29</integer><key>KeyboardLayout Name</key><string>Canadian</string></dict>'
    defaults write "/Users/$u/Library/Preferences/"com.apple.HIToolbox AppleEnabledInputSources -array-add
     '<dict><key>InputSourceKind</key><string>Keyboard Layout</string><key>KeyboardLayout ID</key><integer>80</integer><key>KeyboardLayout Name</key><string>Canadian - CSA</string></dict>'

    # enable on-screen keyboard and character viewers
    defaults write "/Users/$u/Library/Preferences/"com.apple.HIToolbox AppleEnabledInputSources -array-add
     '<dict><key>Bundle ID</key><string>com.apple.CharacterPaletteIM</string><key>InputSourceKind</key><string>Non Keyboard Input Method</string></dict>'
    defaults write "/Users/$u/Library/Preferences/"com.apple.HIToolbox AppleEnabledInputSources -array-add
     '<dict><key>Bundle ID</key><string>com.apple.KeyboardViewer</string><key>InputSourceKind</key><string>Non Keyboard Input Method</string></dict>'

    # fix permissions on plist
    chown "$u":staff "/Users/$u/Library/Preferences/"com.apple.HIToolbox.plist

exit

Forum|alt.badge.img
  • New Contributor
  • 1 reply
  • April 3, 2017

Hello,

I have a Japanese 2012 MacBook Pro. Recently performed a clean install of 10.12.4 and upon booting my jis keyboard is being recognized as a standard US ansi keyboard. Multiple SMC and PRAM resets have no effect. Is there a way to force my Mac to recognize the correct Japanese keyboard?

com.apple.HIToolbox.plist displays the following

bplist00’AppleSelectedInputSourcesAppleEnabledInputSources_AppleInputSourceHistory_'AppleCurrentKeyboardLayoutInputSourceID_AppleDefaultAsciiInputSource°” InputSourceKindKeyboardLayout Name_KeyboardLayout ID_Keyboard Layout[US Extendedˇˇˇˇˇˇˇ˛°” °” _com.apple.keylayout.USExtended” ���/�J�d�é�≠�Ø�∂�»�fi�Ú"$+L���������������������������S


Forum|alt.badge.img+4
  • Contributor
  • 11 replies
  • November 8, 2021
LukeMason wrote:

I have a similar issue.

We typically have both Canadian English and Canadian French as the 2 "enabled" keyboard layouts.

I'm trying to come up with a script that will change the keyboard back to Cdn. English on logout (if the student has changed it to Canadian French during their session). I'm having a heck of a time trying to figure it out.

At this point I'm pretty much overwriting the entire plist with my script, but it still doesn't seem be working.

Here's what I've got:

#!/bin/sh

u=student

    # set the "current" keyboard layout
    defaults write "/Users/$u/Library/Preferences/"com.apple.HIToolbox AppleCurrentKeyboardLayoutInputSourceID com.apple.keylayout.Canadian

    # set the default keyboard
    defaults write "/Users/$u/Library/Preferences/"com.apple.HIToolbox AppleDefaultAsciiInputSource
     -dict InputSourceKind "Keyboard Layout" "KeyboardLayout ID" -int 29 "KeyboardLayout Name" Canadian

    # set the "selected" Input Source
    defaults write "/Users/$u/Library/Preferences/"com.apple.HIToolbox AppleSelectedInputSources -array
     '<dict><key>InputSourceKind</key><string>Keyboard Layout</string><key>KeyboardLayout ID</key><integer>29</integer><key>KeyboardLayout Name</key><string>Canadian</string></dict>'

    # set enabled keyboards (Canadian English & Canadian French)
    defaults write "/Users/$u/Library/Preferences/"com.apple.HIToolbox AppleEnabledInputSources -array
     '<dict><key>InputSourceKind</key><string>Keyboard Layout</string><key>KeyboardLayout ID</key><integer>29</integer><key>KeyboardLayout Name</key><string>Canadian</string></dict>'
    defaults write "/Users/$u/Library/Preferences/"com.apple.HIToolbox AppleEnabledInputSources -array-add
     '<dict><key>InputSourceKind</key><string>Keyboard Layout</string><key>KeyboardLayout ID</key><integer>80</integer><key>KeyboardLayout Name</key><string>Canadian - CSA</string></dict>'

    # enable on-screen keyboard and character viewers
    defaults write "/Users/$u/Library/Preferences/"com.apple.HIToolbox AppleEnabledInputSources -array-add
     '<dict><key>Bundle ID</key><string>com.apple.CharacterPaletteIM</string><key>InputSourceKind</key><string>Non Keyboard Input Method</string></dict>'
    defaults write "/Users/$u/Library/Preferences/"com.apple.HIToolbox AppleEnabledInputSources -array-add
     '<dict><key>Bundle ID</key><string>com.apple.KeyboardViewer</string><key>InputSourceKind</key><string>Non Keyboard Input Method</string></dict>'

    # fix permissions on plist
    chown "$u":staff "/Users/$u/Library/Preferences/"com.apple.HIToolbox.plist

exit

Hey

I was facing a similar problem and found a solution here
Change OSX keyboard layout("input source") programmatically via terminal or AppleScript? 

I used the method with the small m file to compile a little executable with the keyboard layout hard coded in the executable and use a script that runs the executable as the current logged in user. Running the executable as the current logged in user is recommended as each user has an individual keyboard layout. If  you set e.g. US for the admin user (or the user createad/used during enrollment) new users would have British layout again. Both the script and the installation of the package are combined in one policy. 

In my case I added a second script to run it as non-admin. This script checks if the current logged in user is not in the admin group and if so runs the policy. 

 

I hope this helps. 


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings