Skip to content

Instantly share code, notes, and snippets.

Last active December 13, 2022 23:47
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
# Get the currently logged in user
currentUser="$( scutil <<< "show State:/Users/ConsoleUser" | awk '/Name :/ && ! /loginwindow/ { print $3 }' )"
# Check for a logged in user and proceed with last user if needed
if [[ $currentUser == "" ]]; then
# Set currentUser variable to the last logged in user
currentUser=$( defaults read /Library/Preferences/ lastUserName )
# Get the current user's UID
currentUserID="$( id -u "$currentUser" )"
# Nudge plist name
# Get the current OS version
osVersion="$( /usr/bin/sw_vers -productVersion )"
# Get the required minimum OS version from the plist
minOS="$( launchctl asuser "$currentUserID" sudo -u "$currentUser" defaults read $nudgePlist requiredMinimumOSVersion 2>/dev/null )"
# Report info from nudge plist
if [[ $minOS ]]; then
# Check if OS version meets the requirement using zsh is-at-least function
autoload is-at-least
if is-at-least "$minOS" "$osVersion"; then
result="macOS meets minimum required version"
# If not up-to-date, get the number of deferrals from the plist
result="$( launchctl asuser "$currentUserID" sudo -u "$currentUser" defaults read $nudgePlist userDeferrals )"
result="No minimum required macOS version found"
echo "<result>${result}</result>"
Copy link

emily-at-jamf commented May 27, 2022

Heya, I think line 13 is breaking this due to the variable $ at the top of the line.

Copy link

sgmills commented May 31, 2022

Indeed there was a typo there. Should be fixed now, thanks for pointing it out!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment