[go: up one dir, main page]

Skip to content

Neved4/sw_name

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

65 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Shell Script macOS

sw_name - print macOS friendly names! 🚀

Drop-in replacement for sw_vers that simplifies retrieving friendly names in macOS (Ventura, Sonoma).

Motivation

Currently, neither uname -a, sysctl, system_profiler or sw_vers provide this information.

Highlights

  • 🚀 Fast – minimal overhead, sw_name -releaseName function executes in ~ 5.7 ms, of ~ 27 ms total.1
  • 🔒 Robust – accurate output through tests, robust regular expressions and parsing.
  • 📦 Lightweight – self-contained, zero dependencies, uses POSIX awk, sh (1245 bytes, 65 lines).

Getting Started

Note

This utility is only intended to work from OS X 10.9 to macOS 14.0.

Install it with:

$ brew install Neved4/tap/sw_name

Usage

sw_name can be invoked in the following ways:

sw_name
sw_name -releaseName
sw_name -productName
sw_name -productVersion
sw_name -productVersionExtra
sw_name -buildVersion

The following options are available:

usage: sw_name [options]

Options:
    -R, -releaseName, --releaseName
        Prints release name (e.g.: Sonoma, Ventura, Monterey).
    
    -n, -productName, --productName
        Prints product name (e.g.: macOS, Mac OS X).
    
    -v, -productVersion, --productVersion
        Prints product version (e.g.: 12.1, 14.0).
    
    -E, -productVersionExtra, --productVersionExtra
        Prints info specific to certain releases (e.g: (a)).
    
    -b, -buildVersion, --buildVersion
        Prints the build version (e.g.: 23B81, 21A559).

Environment:
    DARWIN_LICENSE
        Specifies the path to a custom license file.

        Example: DARWIN_LICENSE=path/to/license sw_name

Setup

Clone the repository:

git clone https://github.com/Neved4/sw_vers

Add the following to your shell profile (e.g. .bash_profile, .zprofile, .profile):

alias sw_vers='/path/to/sw_vers_name.sh'

Then simply execute it:

$ sw_vers
ReleaseName:    Sonoma
ProductName:    macOS
ProductVersion: 14.5
BuildVersion:   23F79

Then you can use sw_vers normally, with a new -releaseName flag to access macOS friendly names.


Alternatively, if you prefer a concise function, you can add this to your shell profile:

sw_name() {
    awk '/SOFTWARE LICENSE AGREEMENT FOR/ {
        gsub(/.*(macOS|OS X) |\\|.*$0 /, "")
        print
    }' '/System/Library/CoreServices/Setup Assistant.app/Contents/Resources/en.lproj/OSXSoftwareLicense.rtf'
}

And then call the new command:

$ sw_name
Sonoma

Compatibility

Supported macOS Versions

Version Supported
macOS 14 Yes ✅
macOS 13 Yes ✅
macOS 12 Yes ✅
macOS 11 Yes ✅
macOS 10.15 Yes ✅
macOS 10.14 Yes ✅
macOS 10.13 Yes ✅
macOS 10.12 Yes ✅
OS X 10.11 Yes ✅
OS X 10.10 Yes ✅
OS X 10.9 Yes ✅
Supported shells

sw_name uses macOS's /bin/sh by default, but you can run it with other POSIX shells too:

dash /path/to/sw_name.sh

Supported shells

Shell Version Supported
bash 5.2.15 ✅ Yes
dash 0.5.12 ✅ Yes
ksh93 93u+m/1.0.7 ✅ Yes
mksh 59c ✅ Yes
oksh 7.3 ✅ Yes
osh 0.18.0 ✅ Yes
posh 0.14.1 ❌ No
yash 2.55 ✅ Yes
zsh 5.9 ✅ Yes

Acknowledgments

Thanks to @0risc for testing legacy OS X versions.

License

sw_name is licensed under the terms of the MIT License.

See the LICENSE file for details.

Footnotes

  1. cfr. 4.9 ms for sw_vers -productName, tested with hyperfine.