How can I find the “friendly name” of the operating system from the shell / Terminal / bash?

About this Mac with the word 'Mojave' circled

I know that I can use sw_ver to find this information:

ProductName:    Mac OS X
ProductVersion: 10.14
BuildVersion:   18A353d

…and I know I can find other things like uname can give me some types of information about the OS, and system_profiler SPSoftwareDataType can give me additional information, but I want to find the “friendly” name, such as “Mojave” in the image shown above.

How can I find the “friendly” name, using the shell / Terminal / bash / etc ?

So far my Google fu has failed to turn up any solutions. All the results seem to come back to those commands I mentioned above, but none of those give me the right information.

It has to be in there somewhere… how can I find it?


Offline Method

This command should find what you're looking for:

awk '/SOFTWARE LICENSE AGREEMENT FOR macOS/' '/System/Library/CoreServices/Setup Assistant.app/Contents/Resources/en.lproj/OSXSoftwareLicense.rtf' | awk -F 'macOS ' '{print $NF}' | awk '{print substr($0, 0, length($0)-1)}'

It's based off the answer found here. It's tested to work in High Sierra and should work in Mojave.

Online Method

You can also do this online (which is actually what populates "About this Mac" dialog shown in the question):

curl -s https://support-sp.apple.com/sp/product?edid=$( sw_vers -productVersion ) | xmllint --format -xpath "//root/configCode/text()" -

This command will query Apple's server with your poduct version and will extract the OS name from the XML response. To see the full XML response, simply omit the --xpath "//root/configCode/text()" option:

curl -s https://support-sp.apple.com/sp/product?edid=$( sw_vers -productVersion ) | xmllint --format  -

Response:

<?xml version="1.0" encoding="utf-8"?>
<root>
   <name>CPU Name</name>
   <configCode>macOS High Sierra</configCode>
   <locale>en_US</locale>
</root>

Well, I finally gave up looking for a solution -- maybe we'll find one after Mojave hits its final release, but it obviously won't be something that it easily used on older versions of Mac OS X / OS X / macOS.

So I made an alternative to Marc Wilson’s idea (above) and created a shell script which can either output a full list of all of the version numbers and their “friendly names” or will allow you to search for a specific name, for example, if you just want to know which version was called “Yosemite”.

You can find my script here: https://github.com/tjluoma/macosxnames/blob/master/macosxnames.sh

I’ll leave the question open in case we do find a solution that doesn’t require an external script.

Update (over a year later)

Apple now maintains a web page with all of the names and corresponding numbers: https://support.apple.com/en-us/HT201260

You can get the list using this:

(echo "<table>" ; curl -sfLS "https://support.apple.com/en-us/HT201260" \
| tidy --tidy-mark no --char-encoding utf8 --wrap 0 --show-errors 0 --show-warnings no --clean yes --force-output yes --output-xhtml yes --quiet yes \
| sed -e '1,/<table/d; /<\/table>/,$d' -e 's#<br />##g' ; echo "</table>" ) \
| lynx -dump -nomargins -width='10000' -assume_charset=UTF-8 -pseudo_inlines -stdin -nonumbers -nolist

Will give this output:

        macOS         Latest version
macOS Catalina        10.15.2
macOS Mojave          10.14.6
macOS High Sierra     10.13.6
macOS Sierra          10.12.6
OS X El Capitan       10.11.6
OS X Yosemite         10.10.5
OS X Mavericks        10.9.5
OS X Mountain Lion    10.8.5
OS X Lion             10.7.5
Mac OS X Snow Leopard 10.6.8
Mac OS X Leopard      10.5.8
Mac OS X Tiger        10.4.11
Mac OS X Panther      10.3.9
Mac OS X Jaguar       10.2.8
Mac OS X Puma         10.1.5
Mac OS X Cheetah      10.0.4

Then again, Apple isn’t great about keeping documentation online, so it may be gone in a year or two.


set _delim to AppleScript's text item delimiters
set AppleScript's text item delimiters to "."
set os_version to the second item of (the text items of (do shell script "sw_vers -productVersion"))
set AppleScript's text item delimiters to _delim

set osList to { "Puma", "Cheetah", "Jaguar", "Panther", "Tiger", "Leopard", "Snow Leopard",¬
                "Lion", "Mountain Lion", "Mavericks", "Yosemite", "El Capitan", "Sierra", "High Sierra"}

return item (os_version+1) of osList

That's an example.