Last active
May 20, 2019 20:17
-
-
Save AndrewWCarson/2d54bf5c2cec23693251a1234eaeb04e to your computer and use it in GitHub Desktop.
Applies any available updates and prompts any logged-in user to restart.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Modify these strings to change the verbiage in the badge notification. | |
title="Updates Applied" | |
description="macOS updates have been applied to your device. Please restart to complete the process." | |
acceptText="Restart" | |
closeText="Later" | |
if (( $(softwareupdate -l 2>&1 | grep -c ' *') > 0 )); then | |
softwareupdate -ia | |
username=$(/usr/bin/python -c 'from SystemConfiguration import SCDynamicStoreCopyConsoleUser; import sys; username = (SCDynamicStoreCopyConsoleUser(None, None, None) or [None])[0]; username = [username,""][username in [u"loginwindow", None, u""]]; sys.stdout.write(username + "\n");') | |
if [[ "$username" == "" ]]; then | |
echo "No one logged in. Let's restart after updating" | |
(sleep 5 && reboot) &> /dev/null & | |
exit 0 | |
elif /Library/Addigy/macmanage/MacManage.app/Contents/MacOS/MacManage action=notify title="${title}" description="${description}" closeLabel="${closeText}" acceptLabel="${acceptText}"; then | |
echo "User:$username accepted restart." | |
sudo -u "$username" osascript -e 'tell app "loginwindow" to «event aevtrrst»' | |
exit 0 | |
else | |
echo "User:$username delayed restart." | |
exit 0 | |
fi | |
else | |
echo "No available updates for this device." | |
exit 0 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Lots of people have asked me for help with automatically updating macOS devices and prompting the restart. I don't recommend this model, so don't blame me if this breaks things.