Scripting a reboot of Macbook pro

Hi, Looking for some guidance from the pros here! I’ve created two simple cronjobs to reboot my Mac automatically. This has been working for weeks. No changes to the Mac, no upgrades, nothing, but for some reason it stopped rebooting this weekend. It kills the terminal session successfully, but no longer performs the reboot. Any guidance on what I should be doing differently?

43 07 * * * pkill -a Terminal
45 07 * * * osascript -e ‘tell app System Events to restart’

Thanks!!

Cron jobs have been deprecated. Apple prefers you use launchd. Try the program LingonX to create launchd plist files.

Have you considered using the shell’s reboot command? Or shutdown?

As to your osascript command… I don’t think your syntax is correct. I’m surprised that it worked.

1 Like

if this was to work similar to how you have pasted it, you would use full paths and check the quotes which would be straight quotes, both single and double.

45 07 * * * /usr/bin/osascript -e 'tell application "System Events" to restart'

CaptainNewb has requested a cronjob solution, and that has been provided. The following is just for general information on a Calendar app solution.

An AppleScript app can be run on a daily basis by way of the Calendar app. My test script:

display dialog "The computer will restart in 20 seconds" buttons {"Cancel"} cancel button 1 default button 1 giving up after 30
tell application "System Events" to restart without state saving preference

The Calendar app setting that runs the above script is:

On a recent version of macOS, another approach is to create a shortcut:

You can then call the shortcut by way of an AppleScript app as a Calendar event. The first time the Calendar event runs you have to be present to give permission.

tell application "Shortcuts Events" to run shortcut named "Restart Computer"

An alternative approach is to save the shortcut as an app and then to call the shortcut app as a calendar event. This avoids the need for an AppleScript.

When using the shortcut approach, a standard macOS restart dialog is shown:

When creating the Calendar event, it’s important that the start and end times are the same to prevent the script or shortcut from running again and again.

1 Like

Thank you everyone for all of the replies!!! I will give them all a go, thanks!

It was incorrect syntax. I had
45 07 * * * osascript -e ‘tell app System Events to restart’

and it needed to be
45 07 * * * osascript -e ‘tell app “System Events” to restart’

This now works, thank you