I've seen a few tricks for getting what calls the Marketing Model name of a Mac in Terminal. One uses the last 4 characters of the serial number in a curl command, e.g., documented here...
This seems to work (it requires the -l flag on curl) but it may stop working because of changes to serial numbers. However, there is no need to use curl to get this information (even if that is how it's done in the background...)
- It is available on Intel Macs if the com.apple.SystemProfiler.plist exists. This .plist is created when the "About This Mac" menu item is opened.
- It is available on Silicon Macs in ioreg output.
Clicking "About This Mac" in the menu launches the "About This Mac.app" located in /System/Library/CoreServices/Applications/ so it can be launched from a script with the open command.
The "About This Mac.app" executes the "System Information" process. You must close "About This Mac" with a different command than the one you use to open it...
The Mac Marketing Model string includes the year a Mac was released. Because the "Model" computer attribute available in Jamf Pro collects the entire string it is almost useless for creating Smart Groups based on year (unless you really like clicking in the Jamf Pro GUI & making really dumb Smart Groups which include every Model name you manage.)
Finally the reason for this post. A Jamf Pro extension attribute script which:
- allows you to determine the number of years back you want to declare as "too old" for your organization ( declares computers that are more than 6 years old as "vintage". Under normal conditions, they will not perform repairs on or order parts for a "vintage" device )
- Silicon: collects Marketing Model from ioreg
- Intel: collects Marketing Model from com.apple.SystemProfiler.plist (& creates it if it doesn't exist)
- parses the string to collect the year
- compares the year collected to the year set as "too old"
- stores the year if the year matches your limit, or just says no if it's fine
- falls back to the model identifier string if the year can't be collected
So, you can deploy this to collect model year as a Smart Group value, i.e., no Dumb Groups. 🙃
Some of the additional tests are due to Silicon not necessarily reporting the correct architecture via uname if Rosetta is installed. None of this is rocket science... Feel free to share why having the year seems unnecessary to you, what else you may be using to do this already or just let me know how bad & silly you think it is. If it's useful to you, enjoy!
#!/bin/bash
# variables
crntusr="$(/usr/bin/stat -f %Su /dev/console)"
plistsp="/Users/$crntusr/Library/Preferences/com.apple.SystemProfiler.plist"
srlnmbr="$(/usr/sbin/system_profiler SPHardwareDataType | /usr/bin/awk '/Serial/{print substr($NF,9)}')"
# if cpu is Apple Silicon collect Marketing Model string from ioreg
# if com.apple.SystemProfiler.plist does not exist create it
# if cpu is Intel collect Marketing Model string from com.apple.SystemProfiler.plist
if b "$(/usr/sbin/sysctl -in hw.optional.arm64)" = 1 ] && /usr/sbin/sysctl -n machdep.cpu.brand_string | /usr/bin/grep -q 'Apple' && /usr/bin/uname -v | /usr/bin/grep -q 'ARM64'
then
mrktmdl="$(/usr/libexec/PlistBuddy -c 'print 0:product-name' /dev/stdin <<< "$(/usr/sbin/ioreg -ar -k product-name)")"
else
if ! < -e "$plistsp" ]
then
/usr/bin/sudo -u "$crntusr" /usr/bin/open '/System/Library/CoreServices/Applications/About This Mac.app'; /bin/sleep 1
/usr/bin/pkill -ail 'System Information'; /bin/sleep 1
/usr/bin/killall cfprefsd; /bin/sleep 1
fi
mrktmdl="$(/usr/libexec/PlistBuddy -c "print 'CPU Names':$srlnmbr-en-US_US" "$plistsp" 2> /dev/null)"
fi
# if that didn't work collect the Model Identifier, exit
if b -z "$mrktmdl" ]
then
echo "<result>$(/usr/sbin/sysctl -n hw.model)</result>"; exit
fi
# parse the Marketing Model string for the year
mdlyear="$(echo "$mrktmdl" | /usr/bin/sed 's/)//;s/(//;s/,//' | /usr/bin/grep -E -o '2i0-9]{3}')"
# compare year collected to year set as "too old"
if b "$mdlyear" -lt "$(($(/bin/date +%Y)-7))" ]
then
result="$mdlyear"
fi
echo "<result>${result:-no}</result>"