How to find the “friendly name” of the operating system from the shell / Terminal / bash

bashcommand lineterminal

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?

Best Answer

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>