Model Extension Attribute
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on 04-15-2019 02:04 PM
I found a nice extension attribute to pull the Model Identifier
sysModel=sysctl -n hw.model
FullModelName=/usr/libexec/PlistBuddy -c "Print :${sysModel}:LOCALIZABLE:marketingModel" "$plistFile" 2> /dev/null
if [ -z "$FullModelName" ]
then
echo "<result>UNKNOWN</result>"
else
echo "<result>$FullModelName</result>"
fi
exit 0
How can I extract the resulting Year from full model name? Basically i want to extract the info between the opening and closing ( ) in the result.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on 04-16-2019 05:49 AM
So I'm curious why you're after this as an EA? Your JSS will report that natively for you and you can create searches/smart groups/policies based off that already. What's the benefit of the second query? Also your code didn't paste properly, it's missing part of the line to try and assist.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on 04-16-2019 07:50 AM
@easyedc basically I'm trying to extract only the year from the reported Model for each mac..

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on 04-16-2019 10:16 AM
FullModelName=`/usr/libexec/PlistBuddy -c "Print ${sysModel}:_LOCALIZABLE_:marketingModel" "$plistFile" | cut -d"(" -f2 | tr -d ")"`

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on 04-16-2019 02:53 PM
The script you posted isn't complete, because neither the ${sysModel}
or "$plistFile"
variables are defined in it. For the sake of completeness, the ${sysModel}
would be the model identifier, which you can get with something like sysctl hw.model | awk '{print $NF}'
The $plistFile
being referenced is
/System/Library/PrivateFrameworks/ServerInformation.framework/Versions/A/Resources/English.lproj/SIMachineAttributes.plist
which is, as you can see, pretty buried in the OS file system.
Here would be a full Extension Attribute to just get the year from the string that gets returned. Just be aware that this might be fragile. In looking through that plist, I see some older Macs that have no year mentioned in their "marketing model" strings, so there's no telling for sure if it will work with any Mac.
#!/bin/bash
plistFile="/System/Library/PrivateFrameworks/ServerInformation.framework/Versions/A/Resources/English.lproj/SIMachineAttributes.plist"
sysModel=$(sysctl hw.model | awk '{print $NF}')
modelYear=$(/usr/libexec/PlistBuddy -c "Print ${sysModel}:_LOCALIZABLE_:marketingModel" "$plistFile" | tr ' ' '
' | grep -o "20[0-9][0-9]")
if [ ! -z "$modelYear" ]; then
echo "<result>$modelYear</result>"
else
echo "<result>N/A</result>"
fi

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on 07-14-2020 10:48 AM
This is what I used as the file path folders have different names for 10.14. and 10.15.
#!/bin/sh os_ver=$(sw_vers -productVersion | awk -F. '{print $2}') if [[ ${os_ver} -le 14 ]]; then plistFile="/System/Library/PrivateFrameworks/ServerInformation.framework/Versions/A/Resources/English.lproj/SIMachineAttributes.plist" sysModel=$(sysctl hw.model | awk '{print $NF}') modelYear=$(/usr/libexec/PlistBuddy -c "Print ${sysModel}:LOCALIZABLE:marketingModel" "$plistFile" | tr ' ' ' ' | grep -o "20[0-9][0-9]") if [ ! -z "$modelYear" ]; then echo "<result>$modelYear</result>" else echo "<result>N/A</result>" fi elif [[ ${os_ver} -ge 15 ]]; then plistFile="/System/Library/PrivateFrameworks/ServerInformation.framework/Versions/A/Resources/en.lproj/SIMachineAttributes.plist" sysModel=$(sysctl hw.model | awk '{print $NF}') modelYear=$(/usr/libexec/PlistBuddy -c "Print ${sysModel}:LOCALIZABLE:marketingModel" "$plistFile" | tr ' ' ' ' | grep -o "20[0-9][0-9]") if [ ! -z "$modelYear" ]; then echo "<result>$modelYear</result>" else echo "<result>N/A</result>" fi fi exit 0
