Skip to content

Instantly share code, notes, and snippets.

@tjluoma
Last active April 6, 2023 18:40
Show Gist options
  • Save tjluoma/833f7b3ed54b1aad9984b24ca620aa56 to your computer and use it in GitHub Desktop.
Save tjluoma/833f7b3ed54b1aad9984b24ca620aa56 to your computer and use it in GitHub Desktop.
zsh script to compare macOS Versions - see https://rhymeswithdiploma.com/2020/07/10/macos-is-at-least/ for full explanation
#!/bin/zsh -f
# Purpose: Check to see if we are running on Big Sur
#
# From: Timothy J. Luoma
# Mail: luomat at gmail dot com
# Date: 2020-07-10
PATH="/usr/local/bin:/usr/bin:/usr/sbin:/sbin:/bin"
# this will check to make sure `sw_vers` exists
# if it does not, this is probably not macOS
if ((! $+commands[sw_vers] ))
then
echo "$NAME: 'sw_vers' is required but not found in $PATH" >>/dev/stderr
exit 2
fi
## First we get the value for this Mac and save it to `$ACTUAL`
ACTUAL=$(sw_vers -productVersion)
## load 'is-at-least' so we can use it
autoload is-at-least
## "Is the version of macOS that we are using _at least_ 10.16?"
is-at-least "10.16" "$ACTUAL"
## EXIT will be '0' if ACTUAL is at least 10.16
## EXIT will be '1' if ACTUAL is _less than_ 10.16
EXIT="$?"
if [[ "$EXIT" == "0" ]]
then
# This is Big Sur (or later)
echo "YES"
elif [[ "$EXIT" == "1" ]]
then
# This is BEFORE Big Sur
echo "NO"
else
# we should never get here
echo "This should not have happened. EXIT = $EXIT"
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment