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!
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.)
SOFTWARE LICENSE AGREEMENT FOR macOS Sierra\
. The filename thankfully remains the same, though.
– ecmanaut
Mar 03 '17 at 01:02
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
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
.
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-10.12.6
. 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 -Ls "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 -Ls "https://support-sp.apple.com/sp/product?edid=$(sw_vers -productVersion)" |
xmllint --xpath '/root/configCode/text()' -
http://support-sp.apple.com/
method does not work any more for 10.13 and higher.
– Stéphane Mottelet
Mar 25 '19 at 17:33
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.
Perl version:
perl -n -e 's/.*SOFTWARE LICENSE AGREEMENT FOR (?i:macOS|(?:mac\s?)?OS\s*X)\s+(\w+(\s\w+)*).*/$1/ and print' '/System/Library/CoreServices/Setup Assistant.app/Contents/Resources/en.lproj/OSXSoftwareLicense.rtf'
macOS
in the software license agreement file, which may not be present or formatted consistently across all versions of OSX
– karel
Dec 14 '23 at 20:16
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 Problem • http://xyproblem.info/ – sideshowbarker Oct 06 '15 at 01:35