2

Other questions have discussed how to get the numeric name of the current OSX version, ie with "sw_vers -productVersion". However, I know of no way to get the animal word name, like Lion, Mavericks, etc? This word does not appear in Apple / About this mac.

2
  • Why would you need this? There aren't that many versions so it'd be trivial to add a mapping of version number and name to a script.
    – slhck
    Aug 16, 2014 at 1:48
  • 1
    @slhck, maybe I am older than you are :). I first got OSX with the first version and I already cannot remember which was which. A lot of docs only use one or the other notation. I find it incredibly confusing and any scripts I can write/read to deconfuse myself help a lot! Oct 4, 2014 at 16:38

3 Answers 3

1

I'll give you two alternatives. Both have (some) drawbacks, but they work and answer your question.

First solution: make a bash script that contains the animal names. The disadvantage is that you manually have to add an entry if a new version appears. But that's (only) once every 2 years or so.

#!/bin/bash
# Check if bahs supports arrays (only recently added)
test[0]='test' || (echo 'Failure: arrays not supported in this version of bash.' && exit 2)

versions=( "1.0" "10.0" "10.1" "10.2" "10.3" "10.4" "10.5" "10.6" "10.7" "10.8" "10.9" "10.10" )
animals=( "Hera" "Cheetah" "Puma" "Jaguar" "Panther" "Tiger" "Leopard" "Snow Leopard" "Lion" "Mountain Lion" "Mavericks" "Yosemite" )
length=${#versions[@]}
thisversion=`sw_vers | grep -E "ProductVersion" | grep -o '[0-9]*\.[0-9]*' | head -1`
count=0

while [ "${versions[count]}" != "$thisversion" ] && [ "$count" -le "$length" ]
do
    count=$(( $count + 1 ))
done

echo "Your OS X's version animal name is : ${animals[count]}"

Second solution: try to use the information that is on Wikipedia and forge a one-liner-bash-script that gets the animal's name. You'll need a working version of grep, curl, html2text (I installed it using brew), sw_vers, head and awk. Here is her royal nastyness:

curl -s http://en.wikipedia.org/wiki/OS_X | html2text -nobs -ascii | grep -E '^(Mac_)?OS_X.[0-9]{4}.' | grep -f <( sw_vers | grep "ProductVersion" | grep -o '[0-9].[0-9]' | head -1 ) | awk '{ print $2 }'

A little explanation:

  • Get the Wikipedia page using curl
  • Convert it to ascii using html2text
  • Isolate the table with OS X version from the Wikipedia page using grep
  • Then grep the table with the version of OS X you're using
  • Your OS X version comes from sw_vers, which is double-greped and headed to isolate the 2-digit version number
  • Last, but not least, the second column of the Wikipedia table is shown (let's hope they keep the animal names in that column) using awk

Long story short: can it be done? Yes. Is it robust and maintenance free? No.

1
2

While I was looking for a solution to this, I came across this blog post: https://erikberglund.github.io/2016/Apple_Product_Marketing_Name_Query/

As quick summary of the blog post (in case it ever disappears), Apple has a web service you can query for the marketing name of macOS for versions 10.7+. You can supply it with the macOS version number you need the marketing name for and it will return XML with the marketing name.

curl -s "https://support-sp.apple.com/sp/product?edid=10.12.6"

Returns (formatted for display purposes)

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

If you wish to get the marketing name for the version of macOS that you are currently running, you can run the one liner

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

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

1
  • 1
    1.I wonder can I / should I change to accept this answer? it is really great! ; 2.The one liner on my terminal printed over my line prompt characters. So to clarify the output, I added a dummy echo, ie: curl -s support-sp.apple.com/sp/product?edid=$(sw_vers -productVersion) | xmllint --xpath '/root/configCode/text()' - ; echo "" Sep 26, 2017 at 3:19
1

The animal names are for marketing purposes only. Running terminal and making queries will only result in numeric references, much like the language is limited to unix-based terminology.

You must log in to answer this question.

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