Category filter

Script to shutdown Mac

Users will typically select the Apple icon from the menu bar and select Shut Down to shut down a Mac. However, there are very few options available in the process, and device admins might want to execute such an operation remotely.

Hexnode already provides admins with the option to Power off devices from the console with a click, but with the below shell scripts, you can achieve even more granular control and automation over the shutdown power option on Mac.

Device admins can remotely run scripts on Macs managed with Hexnode using the Execute Custom Script action.

Scripting Language – Bash

File extension – .sh

Disclaimer:


The sample scripts provided below are adapted from third-party open-source sites.

Boot options on Mac

The shutdown command provides an automated shutdown procedure to close down the system at a given time. Some of the options supported with the command are –

-r

  • The system gets rebooted at the specified time.

-h

  • The system is halted at the specified time.

-s

  • This option will simply turn off the display and lock the device.

Note that the options -r, -h, and -s cannot be used simultaneously.

Time:

This parameter is used to specify the time at which the system will execute the shutdown command.

  • To execute the action immediately, pass the value now.
  • To schedule the action, use the format +number (in minutes).
  • To schedule the action at a specific time, use the format yymmddhhmm.

Warning message:

Any other arguments not having a function are passed as the warning message. The warning message can be passed in the command following the time parameter.

Examples:

Script to reboot Mac instantly:

This script will shut down the device instantly.

Script to reboot Mac in 5 minutes:

This command will reboot the device in 5 minutes.

Script to shutdown Mac at a specified time:

This command will schedule shutdown on October 18, 16:11:00 2022.

Script to reboot Mac with a warning message:

This command will reboot the device in 2 minutes and the warning message, “the system will restart in 2 minutes” will be passed before the reboot action.

Notes:

  • It is recommended to manually validate the script execution on a system before executing the action in bulk.
  • Hexnode will not be responsible for any damage/loss to the system on the behavior of the script.

  • Sample Script Repository