Posted on 11-24-2011 07:51 AM
We have MacBooks with different keyboard layouts,
so an extension attribute pulling the info which keyboard is actually built into a laptop would be quite helpful.
Anyone have a hint on how to do this?
I have compared the Product IDs of different keyboards in System Profiler,
but couldn't find any consistency...
Any help would be appreciated :)
Posted on 11-25-2011 06:04 AM
Are you looking for something that shows different keyboards, or the different keyboard layouts, like the ones in system preferences > Language & Text > Input Sources? Are you looking for both?
Posted on 11-25-2011 06:13 AM
I'm looking for the physical keyboard layout.
Hardware wise, not what is set in "Input Sources".
I'd like to be able to tell which MacBooks have a German keyboard (QWERTZ)
and which have a US keyboard (QWERTY) etc...
Sorry if that was unclear.
Posted on 11-25-2011 06:43 AM
No worries. Probably me, not enough coffee yet.
Ok, I have found where you can get the input sources. Are these keyboard types ordered this way, or are you talking about physically connected external keyboards. (time for more coffee).
Posted on 11-25-2011 07:42 AM
*passing coffee to Sean*
For now I'm only interested in the internal keyboards.
As we have people from all over the world working here,
we order some MBs with German keyboards, some with U.S. keyboards,
and there's a couple UK and Japanese floating around also.
Of course i could go through the packing slips and fill my inventory manually,
but I'd prefer a script doing that for me ;)
Posted on 09-03-2015 02:02 PM
Another "Dead Thread Thursday".....
@Chris - did you find an effective way to do this?
Posted on 09-07-2015 06:17 AM
Hey @tep , no, unfortunately not.
What we're doing now is manually populate an EA with the keyboard layout
and then have a script set the layout in OS X according to the EA's value.
Posted on 09-09-2015 01:25 AM
What happens if you run this on the different machine models?
#!/bin/bash
serial_number=`system_profiler SPHardwareDataType | awk '/Serial Number/ {print substr($NF,9,4)}'`
curl -s http://support-sp.apple.com/sp/product?cc=$serial_number | sed 's|.*<locale>(.*)</locale>.*|1|'
exit 0
I also notice that the keyboard appears to have a country code
ioreg -c AppleEmbeddedKeyboard | sed -n '/AppleEmbeddedKeyboard/,/CountryCode/p'
Posted on 09-09-2015 02:06 AM
Unfortunately the last four of the serial are always the same for one model, no matter which keyboard.
http://support-sp.apple.com/sp/product?cc=$serial_number will report en_US by default,
or de_DE if you append &lang=de_DE to the URL for example.
I also always get "13" as the Country Code from ioreg :(
Posted on 09-09-2015 03:06 AM
What about this Python script? It isn't immediately what you are after, but you should get different answers. It would involve user input, akin to when Apple asks you to push the key immediately left of the Z key.
Posted on 10-12-2015 05:33 AM
@Chris I also have a need to find the physical layout of the keyboard on our MacBook Air/Pro inventory. Any luck so far?
Posted on 10-12-2015 05:43 AM
Sorry, haven't really looked into this any more.
I guess using a script with user input as mentioned above is the only way.
Posted on 07-31-2019 10:44 AM
Hey, I came across the same need a few weeks ago (I know it's been a while, sorry). I think this can be the start for a full stack solution (haven't tested if it is affected by plugging an external kb with another physical layout).
If I run this:
defaults read ~/Library/Preferences/com.apple.HIToolbox.plist AppleSelectedInputSources | egrep -w 'KeyboardLayout Name'
I definetly get the Input Source, so software, in my case "Spanish - ISO"
But if I run this: ioreg -l | grep KeyboardLanguage | cut -d" -f 4
I'm pretty sure I get the physical layout here, in my case "Spanish - ISO"
I run this last command in another macbook, with a physical kb UK layout and an "Spanish - ISO" (only) Input Source and I get "British"
If anyone is certain that I'm wrong here, please let me know.
Thanks,
Federico.
Posted on 08-01-2019 11:01 AM
I came up with a solution, but it requires Python 3 + Objective C bridge, but it works and I am using it to track keyboard types now
#!/opt/snowflake/bin/python3
# you will need to set the path to your python 3 env above as mine probably does not exist in your env
# REQUIRES Python 3 + Objc Bridge
# import modules
import plistlib
from SystemConfiguration import SCDynamicStoreCopyConsoleUser
from Foundation import NSHomeDirectoryForUser
# global vars
USER, UID, GID = SCDynamicStoreCopyConsoleUser(None, None, None)
USERHOME = NSHomeDirectoryForUser(USER)
FILE = USERHOME + '/Library/Preferences/com.apple.HIToolbox.plist'
# script logic
with open(FILE, 'rb') as f:
data = plistlib.load(f)
keyboard = data['AppleEnabledInputSources'][0]['KeyboardLayout Name']
print(f'<result>{keyboard}</result>')
my code results
/opt/snowflake/bin/python3 /Users/tlarkin/IdeaProjects/tlarkin/get_keyboard_layout.py
<result>U.S.</result>
If you are interested in building and shipping Python 3 to your fleet, I used this nifty tool from Greg and started shipping Python 3 to my entire fleet the day after Catalina beta was released in preparation of all the changes and EOL of Python 2.
Posted on 01-11-2021 08:05 PM
For those using osquery-like tools, I added an extended attribute with the following command:
keyboardType=$(/usr/local/bin/osqueryi --csv --header=no "select value from plist where path = '/Library/Preferences/com.apple.HIToolbox.plist' and value like '%keylayout%';")
echo "<result>$keyboardType</result>"