Set night time updates on Mac OS

These instructions are useful to set your Mac OS to check for updates during night-time hours or during off peek internet usage.

We need to create a plist and then schedule it to run. To start.

Create the Plist file:

This is the LaunchDaemon plist file; just save it as myfile.plist in /Library/LaunchDaemons.

You can, of course, adjust the schedule according to your own wishes.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>Label</key>
    <string>info.softwareupdate</string>
    <key>ProgramArguments</key>
    <array>
    	<string>/usr/local/sbin/softwareupdate</string>
    </array>
    <key>StartCalendarInterval</key>
    <dict>
    	<key>Minute</key>
        <interger>0</integer>
        <key>Hour</key>
        <integer>2</integer>
    </dict>
</dict>
</plist>
PLIST Contents

Set Permissions on Plist:

Ensure you set root permissions on the Plist so it can run.

sudo chown root /Library/LaunchDaemons/myfile.plist
sudo chgrp wheel /Library/LaunchDaemons/myfile.plist
Set Permissions

Create the Script:

Here is the "softwareupdate" script that does the dirty work. Put it in /usr/local/sbin, or somewhere else on your path. If you store it elsewhere or change the script name, change the path in the above plist file to point to the new location.

This script does two things, it creates a system notification that an update check is about to happen. Then is checks for all mandatory and optional updates. You can change the notifications sgrings to your liking. Check out the documentation on Mac OS's softwareupadte utility to learnmore about the shown arguments and other arguments or options that may apply to your unique needs.

#!/bin/zsh

oasscript -e 'display notification "Checking for system updates and restarting" with title "Scheduled Update"'
/usr/sbin/softwareupdate --install --all --restart
ZSH Script

Set Execute on the Script:

Remember to chmod +x the script file, so it can run. Note that this script is using Zsh not Bash. Zsh is now the preferred default shell on Mac OS. To ensure the script is set to as executable run:

Chmod +x %path to your script%

You can check that your service is available by running:

sudo launchctl list

Scroll thru the list of services and look for "info…".

Wrapping up

At this point you need to make sure the Mac is awake at the scheduled time and it will automatically check for updates, download and install. It will restart as necessary.