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
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:
1 2 |
#!/bin/bash sudo shutdown -h now |
This script will shut down the device instantly.
Script to reboot Mac in 5 minutes:
1 2 |
#!/bin/bash sudo shutdown -r +5 |
This command will reboot the device in 5 minutes.
Script to shutdown Mac at a specified time:
1 2 |
#!/bin/bash sudo shutdown -h 2210181611 |
This command will schedule shutdown on October 18, 16:11:00 2022.
Script to reboot Mac with a warning message:
1 2 |
#!/bin/bash sudo shutdown -r +2 "the system will restart in 2 minutes" |
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.