Can a Mac's model year be determined with a Terminal Command?

You can indirectly get this information from a web page and the curl command. In the past this URL has been taken down and rate limited and put behind some sort of captcha to prevent this use, so you might need to resort to other avenues like https://checkcoverage.apple.com/ in that case.

Depending on if your serial numer is 11 or 12 characters long take the last 3 or 4 characters, respectively, and feed that to the following URL after the ?cc=XXXX part. If your serial number was 12 character and ended in DJWR, you would issue this command:

curl https://support-sp.apple.com/sp/product?cc=DJWR

To get your serial number, use the following command:

system_profiler SPHardwareDataType | awk '/Serial/ {print $4}'

Thus, you could have a complicated command to query the internet if you need a single command:

curl https://support-sp.apple.com/sp/product?cc=$(
  system_profiler SPHardwareDataType \
    | awk '/Serial/ {print $4}' \
    | cut -c 9-
)

and then run the output of that through sed to cut to the key part

curl -s https://support-sp.apple.com/sp/product?cc=$(
  system_profiler SPHardwareDataType \
    | awk '/Serial/ {print $4}' \
    | cut -c 9-
) | sed 's|.*<configCode>\(.*\)</configCode>.*|\1|'

There used to be a private library file with these mappings so you could consult it offline, but I noticed it was gone as of 10.8.3 (and perhaps earlier) so the above trick is the only one I know that works on the current OS without third party libraries.

Some nice third party libararies provide a look up of this:

  • python code https://github.com/MagerValp/MacModelShelf
  • JSON mapping https://github.com/krypted/swiftwarrantylookup/blob/master/src/swiftMacWarranty/model_snippets.json

Note that as of November 2017, Apple has forced the use of https over http for this service.


You can use the command

system_profiler SPHardwareDataType | grep "Model Identifier"

in Terminal to get the model ID of your machine.
Then you can enter that ID on this site which will list the month and year the particular model was launched.

As mentioned in the comments below, the following command is much faster:

sysctl hw.model

On El Capitan and Sierra, there's a plist file in a private framework with a dict of info for each model identifier; that dict includes the marketing name (which has the model year in it). I don't know what OS version that particular file came in with, but it's NOT on Snow Leopard (the only thing I have that's older than El Capitan).

#! /bin/ksh
if [ -f /System/Library/PrivateFrameworks/ServerInformation.framework/Versions/A/Resources/English.lproj/SIMachineAttributes.plist ]
then
    marketingModel="$(modelid="$(system_profiler SPHardwareDataType 2>/dev/null|awk '/Model Identifier:/ {print $NF}')"
    defaults read /System/Library/PrivateFrameworks/ServerInformation.framework/Versions/A/Resources/English.lproj/SIMachineAttributes.plist "MacBookPro12,1"|sed -n -e 's/\\//g' -e 's/.*marketingModel = "\(.*\)";/\1/p')"
    echo "${marketingModel}"
else
    echo "can't use offline method to find marketing name on this OS version"
fi

So, you could use that (or other similar tricks for other OS versions after checking the OS version, if you know those tricks, which I don't), and if that wasn't applicable, you could always fall back to the approach that requires Internet access.

This is not exactly the same as what About This Mac shows, which in my case is
MacBook Pro (Retina, 13-inch, Early 2015)
while this shows
13" MacBook Pro with Retina display (Early 2015)
but in human-readable terms, I think it's close enough.


Here is a one liner using PlistBuddy, without any grep, sed or awk-wardness.

/usr/libexec/PlistBuddy -c "print :$(sysctl -n hw.model):_LOCALIZABLE_:marketingModel" /System/Library/PrivateFrameworks/ServerInformation.framework/Versions/A/Resources/English.lproj/SIMachineAttributes.plist

this returns something like:

15" MacBook Pro with Thunderbolt 3 and Touch ID (Mid 2017)

-

Another one liner that yields a slightly different string, also using PlistBuddy (with a tiny bit of awk):

/usr/libexec/PlistBuddy -c "print :'CPU Names':$(system_profiler SPHardwareDataType | awk '/Serial/ {print $4}' | cut -c 9-)-en-US_US" ~/Library/Preferences/com.apple.SystemProfiler.plist

MacBook Pro (15-inch, 2017)

Credit to several of the above answers for this.