Category filter
Execute custom scripts to set date and time for macOS devices
Changing the date or time on a Mac requires the user to customize the Date & Time settings from the System Preferences or System Settings. Enforcing a date and time is extremely critical in enterprise settings where accurate timestamps are necessary for logging and tracking. Setting the date and time on macOS devices deployed for work can be efficiently automated using scripts. As an administrator, if you want to force the date or time on Macs without involving repetitive user interaction, you can execute the following scripts using the
Execute Custom Script action.
Scripting language – Bash
File extension – .sh
Set Date and Time
On macOS, the shell scripting language commonly used is Bash. Here’s an example of a Bash script:
1 2 3 |
#!/bin/sh date 120614302023.00 |
Suppose to set the date and time of a device to 6 December 2023 2:30 pm, the command takes the following form:
date 120614302023.00
The basic script presented above uses the date command. The date command is followed by the value that specifies the date and time in the required format. The format used is MMDDhhmm[[CC]YY][.ss]
, where:
MM – the month of the year
DD – the date of the month
hh – the hour
mm – the minutes
CC – the first two digits of the year (century)
YY – the last two digits of the year
ss – the seconds
You may also use the following script if you want to pass the value for date and time as arguments. While executing the script, you may specify the date and time in the same format MMDDhhmm[[CC]YY][.ss] in the Arguments field.
1 2 |
#!/bin/sh date $1 |
You can verify the status of the script execution from the Action History tab of the device in the Hexnode UEM portal. Navigate to the Manage tab and click on the device. Along with the Device Summary sub-tab, there are other sub-tabs, including Action History. Go to Action History and verify the status of the given action.