7

Is there a way to get OSX codename (I.e. Yosemite, El Capitan etc) from command line? I'm not looking for Version information (e.g.

sw_vers -productVersion

) which gives 10.10 etc Thanks!

  • 2
    I think there’s no reliable way to do this from within bash (Terminal). Even system_profiler (which spits out a pretty exhaustive set of info) doesn’t include those names (which I think Apple calls the “marketing version”). Maybe you’re trying to solve a problem by looking for that codename? If so, be careful you’re not falling into the XY Problemxyproblem.info – sideshowbarker Oct 6 '15 at 1:35
  • 1
    Aren't there only ten of them? Why not just get the version information and translate it using a hardcoded lookup table? – Wildcard Oct 6 '15 at 6:16
  • @wildcard: this is what I've been doing so far but every time a new version come out I have to update and redistribute my library... Or do you already know the future names? – lviggiani Oct 7 '15 at 21:55
5

I'm sure there's got to be an easier and more-reliable way, but at least you can eliminate the pipe to sed altogether by using grep with -o (prints only matches) and -E (extended regular expressions):

grep -oE 'SOFTWARE LICENSE AGREEMENT FOR OS X.*[A-Z]' '/System/Library/CoreServices/Setup Assistant.app/Contents/Resources/en.lproj/OSXSoftwareLicense.rtf'

This does, however, also return the SOFTWARE LICENSE AGREEMENT FOR OS X portion of the output. If you just want the codename, you could pipe it to sed, but it would not require any back-references using the dreaded -E flag that BSD sed is so infamous for:

grep -oE 'SOFTWARE LICENSE AGREEMENT FOR OS X.*[A-Z]' '/System/Library/CoreServices/Setup Assistant.app/Contents/Resources/en.lproj/OSXSoftwareLicense.rtf' | sed "s/SOFT.*OS X //"

Personally, I prefer the awk method instead:

grep -oE 'SOFTWARE LICENSE AGREEMENT FOR OS X.*[A-Z]' '/System/Library/CoreServices/Setup Assistant.app/Contents/Resources/en.lproj/OSXSoftwareLicense.rtf' | awk -F 'OS X ' '{print $NF}'

Pure awk solution:

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

(I'm sure there's a way to do it without piping to additional awk processes, but I'm not a pro.)

  • In at least macOS Sierra, you need to remove the " OS X" portion from these, as the line now reads `SOFTWARE LICENSE AGREEMENT FOR macOS Sierra`. The filename thankfully remains the same, though. – ecmanaut Mar 3 '17 at 1:02
1

FWIW, here’s a fugly hacky way; it’s probably neither very forward- nor backward-compatible:

grep "SOFTWARE LICENSE AGREEMENT FOR OS X" \
  "/System/Library/CoreServices/Setup Assistant.app/Contents/Resources/en.lproj/OSXSoftwareLicense.rtf" \
  | sed -E 's/^SOFTWARE LICENSE AGREEMENT FOR OS X (.+)\\$/\1/'

It works at least on the El Capitan and Mavericks systems I checked (and so I would assume on Yosemite). It returns the marketing name in all caps; e.g., EL CAPITAN and MAVERICKS.

1

From this blog post, I learned that 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 http://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 http://support-sp.apple.com/sp/product?edid=$(sw_vers -productVersion) |
xmllint --xpath '/root/configCode/text()' -
  • The http://support-sp.apple.com/method does not work any more for 10.13 and higher. – Stéphane Mottelet Mar 25 at 17:33
1

How about this :

$ sed -nE '/SOFTWARE LICENSE AGREEMENT FOR/s/([A-Za-z]+ ){5}|\\$//gp' /System/Library/CoreServices/Setup\ Assistant.app/Contents/Resources/en.lproj/OSXSoftwareLicense.rtf
0

Struggled for a consistent way to retrieve this information across OS X versions. Apple moved the location of: OSXSoftwareLicense.rtf in High Sierra. Rather than use regular expressions to hit a target that might move, I devised the following:

#!/bin/bash
# Retrieve Apple's marketing name for installed operating system 

# Take the number extracted from here; use it as a reference

osx_num=$(sw_vers -productVersion| awk -F '[.]' '{print $2}')

# Lookup table for OS X marketing names 

OSX_MARKETING=(
["10"]="Yosemite"
["11"]="El Capitan"
["12"]="Sierra"
["13"]="High Sierra"
)

# Check if the number extracted is in array; 
# if it is, print marketing name

osx_name () {
  if [[ -n "${OSX_MARKETING[$osx_num]}" ]]; then 
    printf "%s\\n" "${OSX_MARKETING[$osx_num]}"
fi
}

This works reliably on the four most-recent versions of OS X, and probably others.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.