4

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?

  • 1
    Pointing out that the correct answer would just be retrieve the number via whatever method, and have your own lookup table for the name. – Marc Wilson Aug 12 '18 at 0:35
  • 1
    I'm filing a radar against sw_ver since this marketing name clearly should be emitted from that command. I've done a lot of spelunking looking for this and I'm guessing you'll need a very oblique way to get this from installed updates with the name. – bmike Aug 12 '18 at 0:47
  • 1
    Why? It's easily determinable, the names are all known and all you have to do is index into a list. I provide a (bad) Applescript below. – Marc Wilson Aug 12 '18 at 0:55
3

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>
  • Unfortunately it gives me “High Sierra” as output on my Mojave machine. The word 'Mojave' doesn't appear in the file. – TJ Luoma Aug 12 '18 at 1:45
  • also, from that same link, someone suggested this, which also does not work (returns nothing): VER="$(sw_vers -productVersion)"; curl -s "http://support-sp.apple.com/sp/product?edid=$VER" – TJ Luoma Aug 12 '18 at 1:46
  • 1
    It's probably because they haven't updated the file for Mojave, yet. The online service seems to no longer work as I cannot get it to respond to any query. That one will take more digging – Allan Aug 12 '18 at 1:51
  • I was able to get the second one functioning. You need https as Apple will ignore non-ssl connections. I also added the xmllint filter to extract the data you're looking for. – Allan Aug 12 '18 at 2:23
  • 1
    I don't have a pre-Sierra machine to check, but wouldn't the "offline" method above fail, pre-Sierra? It didn't call itself "macOS" before that. I'm not a fan of solutions where the machine is required to have an Internet connection. – Marc Wilson Aug 12 '18 at 14:31
1
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.

  • 2
    The script indeed solve the purpose, but isn't scalable. It will have to be updated with each major release of macOS. The intent seems to be figuring out a mechanism build into macOS (or using the information built into OS) which can reveal the marketing name of the release. – Nimesh Neema Aug 12 '18 at 1:03
  • 1
    @NimeshNeema it is however the only solution that gives the correct answer – Mark Aug 12 '18 at 12:55
  • As long as you're shelling out, you can use the following to replace the first 4 lines of your script: set os_version to (do shell script "sw_vers -productVersion | awk -F. '{print $2}'") – user3439894 Aug 21 '18 at 17:17
  • Really, if I were going to do that, I'd do the whole thing in awk. :) I like awk. – Marc Wilson Aug 22 '18 at 20:18
0

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .