Posted on 02-06-2020 01:19 AM
Hello,
I would need a script for an attribute extension which I would use to trace what type of keyboard is used on computers and to create smart groups.
Do you have any ideas ?
Thank you.
Posted on 02-06-2020 04:08 AM
To what end are you wanting to gather this information? The settings involved are stored at a user level, so populating an extension attribute with the value isn't the easiest thing. The preference holding the keyboard info is com.apple.HIToolbox.plist If you simply wanted to set a default keyboard layout then a custom configuration profile would work. The settings, depending on your region etc, would look something like:
<?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>
</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>
You can read in the info from this plist, but any code will fail when a user isn't logged in, making it iffy to use for scoping, especially when you add in the fact that a multi-user system could have multiple answers...
Posted on 02-06-2020 05:14 AM
Hi,
I do not wish to define a setting but to provide information for my inventory.
If it's possible :)
Regards,
Posted on 02-06-2020 05:47 AM
Sorry, are you wanting to gather the physical type of keyboard attached to a Mac, or the keyboard layout/language that a user is using?
For the physical device; "ioreg -p IOUSB" is probably the best bet, but actually working out a sensible match isn't always obvious... For example:
CHERRY KEYBOARD@14500000 <class AppleUSBDevice, id 0x1000003b7, registered, matched, active, busy 0 (0 ms), retain 13>
USB Keyboard@14300000 <class AppleUSBDevice, id 0x10000034b, registered, matched, active, busy 0 (0 ms), retain 13>
Apple Keyboard@14420000 <class AppleUSBDevice, id 0x1000003ac, registered, matched, active, busy 0 (0 ms), retain 13>
Are all keyboards... "system_profiler SPUSBDataType" might be more human readable, but will also be harder to filter.
For the language, you would need to pull the info from that plist. Something like: defaults read com.apple.HIToolbox AppleSelectedInputSources | grep "KeyboardLayout Name"
Note this code would need to be ran as the user, or you would need to specify the full path /Users/USERNAME/Library/Preferences/com.apple.HIToolbox