brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: sw_vers prints your macOS version and build number

macOS
~/tips/tip-macos-sw-vers-version-build

sw_vers

Prints the macOS product name, version and build number, or just one of them for scripts.

When a guide says “works on macOS 15.2 and later”, I want my version without opening a menu. One command prints it.

sw_vers
sw_vers -productVersion
sw_vers -buildVersion

Plain sw_vers prints the product name, the version and the build, three lines. -productVersion and -buildVersion print only that value, which is exactly what you want in a script. The man page also documents -productName and -productVersionExtra.

The build number is the one you need for beta releases, or when Apple ships two builds with the same version number. It looks like 22A100, and bug reports and release notes often name it.

A small script that checks a minimum version:

[ "$(printf '%s\n' 14.0 "$(sw_vers -productVersion)" | sort -V | head -n1)" = 14.0 ] && echo ok

The caveat is that the sort -V trick needs a sort that supports version sort, which recent macOS has. And do not read the kernel version from uname -r as the macOS version: they are different numbers. Apple’s own man page for sw_vers mentions an environment variable for old compatibility behaviour, and a developer forum thread says newer macOS versions no longer honour it, so the output reflects the real system version.

Further reading: sw_vers(1) manual

More macOS tips System Settings > Accessibility > Hover Text > When using the pointer A Smart Folder in Notes collects notes by tag, checklist or date Type # in a Mac note to tag it, then filter by tag in the sidebar tmutil isexcluded ~/Projects/app/node_modules Crop an image in Preview by dragging a frame and clicking Crop All macOS tips (99) All topics

Link