Skip to content

Neved4/sw_name

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

62 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).

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 tried 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.

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

With the following options and environment:

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.1
BuildVersion:   23B74

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. ↩