Skip to main content
Question

Add input source to keyboard settings via script


Forum|alt.badge.img+3

Hi all,

Does anyone know how to add a second input source to the keyboard? I have the keyboard ID, but don't know how to add it to the input sources?

I would also like to show the input menu in menu bar for users.

Thanks in advance for any guidance.

8 replies

chrisdaggett
Forum|alt.badge.img+7
  • Valued Contributor
  • 94 replies
  • November 12, 2019

@donifar Also have a need for this but have yet to find any solution. Surprised this isn't more common.


dsavageED
Forum|alt.badge.img+8
  • New Contributor
  • 168 replies
  • November 13, 2019

We used to reset these settings to our defaults on lab Macs in the past. I'd suggest you want to do this via a custom configuration profile as these settings are user level. Scripting them will be far more complex than deploying a config profile.

To add the Menu bar option the preference is com.apple.systemuiserver.plist the necessary plist content is:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
    <dict>
        <key>menuExtras</key>
        <array>
            <string>/System/Library/CoreServices/Menu Extras/TextInput.menu</string>
        </array>
        <key>NSStatusItem Visible com.apple.menuextra.textinput</key>
        <true/>
    </dict>
</plist>

The preference holding the keyboard info is com.apple.HIToolbox.plist, add your required keyboards in the System Preferences then, again, use this to create a custom config profile. For example, British and Australian, with British as default would be:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
    <dict>
        <key>AppleCurrentKeyboardLayoutInputSourceID</key>
        <string>com.apple.keylayout.British</string>
        <key>AppleEnabledInputSources</key>
        <array>
            <dict>
                <key>InputSourceKind</key>
                <string>Keyboard Layout</string>
                <key>KeyboardLayout ID</key>
                <integer>2</integer>
                <key>KeyboardLayout Name</key>
                <string>British</string>
            </dict>
            <dict>
                <key>InputSourceKind</key>
                <string>Keyboard Layout</string>
                <key>KeyboardLayout ID</key>
                <integer>15</integer>
                <key>KeyboardLayout Name</key>
                <string>Australian</string>
            </dict>
        </array>
        <key>AppleSelectedInputSources</key>
        <array>
            <dict>
                <key>InputSourceKind</key>
                <string>Keyboard Layout</string>
                <key>KeyboardLayout ID</key>
                <integer>2</integer>
                <key>KeyboardLayout Name</key>
                <string>British</string>
            </dict>
        </array>
    </dict>
</plist>

talkingmoose
Forum|alt.badge.img+36
  • Legendary Contributor
  • 1900 replies
  • February 19, 2020

Recently had someone point me to this question. It's possible to use the defaults command to add an input source. I have an example on GitHub.

Here's a short script:

#!/bin/zsh

# adds the additional input source to the list of input sources
/usr/bin/defaults write com.apple.HIToolbox AppleEnabledInputSources -array-add '<dict><key>InputSourceKind</key><string>Keyboard Layout</string><key>KeyboardLayout ID</key><integer>89</integer><key>KeyboardLayout Name</key><string>Latin American</string></dict>'

# enables the input menu in the menu bar
/usr/bin/defaults write com.apple.TextInputMenu visible -bool true

exit 0

Forum|alt.badge.img+1
  • New Contributor
  • 1 reply
  • October 6, 2020

Any one can tell me how to find out the keyboard ID


Forum|alt.badge.img+8
  • Contributor
  • 25 replies
  • November 27, 2020

@luic6 try this. defaults read /Library/Preferences/com.apple.HIToolbox.plist AppleEnabledInputSources


Forum|alt.badge.img+8
  • Contributor
  • 25 replies
  • November 27, 2020

@talkingmoose I used your script, thnx for that. Now when I open my system prefs I have 2 how do I make the just added one default? Or how can I remove one?

thnx


Forum|alt.badge.img+1

@talkingmoose jamf should give the smartest way to do it...


dlondon
Forum|alt.badge.img+14
  • Honored Contributor
  • 374 replies
  • January 15, 2024
talkingmoose wrote:

Recently had someone point me to this question. It's possible to use the defaults command to add an input source. I have an example on GitHub.

Here's a short script:

#!/bin/zsh

# adds the additional input source to the list of input sources
/usr/bin/defaults write com.apple.HIToolbox AppleEnabledInputSources -array-add '<dict><key>InputSourceKind</key><string>Keyboard Layout</string><key>KeyboardLayout ID</key><integer>89</integer><key>KeyboardLayout Name</key><string>Latin American</string></dict>'

# enables the input menu in the menu bar
/usr/bin/defaults write com.apple.TextInputMenu visible -bool true

exit 0

Thanks @talkingmoose that works great.  What I noticed though is that you don't see the change until after you logout and log back in.  I tried restarting the menu bar using

killall -KILL SystemUIServer

and it did restart the menubar but didn't load the added input source.  Any ideas on whether it is possible to reload that list without the logout/login?


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