Skip to content

Instantly share code, notes, and snippets.

@Integralist
Last active September 18, 2020 11:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Integralist/143faf7ca6b8090e112ec0752ff7e1ca to your computer and use it in GitHub Desktop.
Save Integralist/143faf7ca6b8090e112ec0752ff7e1ca to your computer and use it in GitHub Desktop.
[macOS System Information] #macos #system #information #shell #bash
# Documentation:
#
# - man sw_vers
# - man system_profiler
#
# Product Name:
# Neither of the above solutions provide the OS 'product name' (e.g. Catalina, Mojave, High Sierra etc.)
# So I curl Wikipedia's macOS version history page and parse out the name.
#
# The problem in doing so is that I need a version number (e.g. 10.15)
# but the version number provided by `sw_vers -productVersion` is the full version (e.g. 10.15.16)
# meaning we need to strip the last segment (this is done with the following bash trick: `${version%.*}`)
# also when grepping for the product name it comes up twice in the Wikipedia page, so I use `uniq` to remove duplicates
alias sys='sw_vers && echo && system_profiler SPSoftwareDataType && curl -s https://en.wikipedia.org/wiki/MacOS_version_history | grep -Eo "Version $(version=$(sw_vers -productVersion) && echo ${version%.*}): \"[^\"]+\"" | uniq'
# Example Output:
#
# ProductName: Mac OS X
# ProductVersion: 10.15.6
# BuildVersion: 19G2021
#
# Software:
#
# System Software Overview:
#
# System Version: macOS 10.15.6 (19G2021)
# Kernel Version: Darwin 19.6.0
# Boot Volume: Macintosh HD
# Boot Mode: Normal
# Computer Name: Integralist-MBPr
# User Name: Integralist (integralist)
# Secure Virtual Memory: Enabled
# System Integrity Protection: Enabled
# Time since boot: 3 days 2:37
#
# Version 10.15: "Catalina"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment