Category filter

Script to set time zone for Mac

A macOS device automatically configures the time zone under the Date & Time preferences depending on its current location. However, if you want to specify the time zone of a device over the air, you can get it done with the help of scripts. The
Execute Custom Script
action from Hexnode streamlines this process where you run customized scripts directly from the UEM console.

Scripting language – Bash

File extension – .sh

Disclaimer:

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

Set time zone

Replace $1 with your preferred time zone and deploy the above custom script from the Hexnode UEM console to the device.

Consider the following script. It explicitly sets the device’s time zone to “Pacific/Ponape”:

There is a possibility that your device still shows the incorrect date and time even after setting the time zone. This might be because you have not enabled the Set date and time automatically option on the device. Either enable this option manually on the device or deploy the script given below from the Hexnode console to the device to automatically adjust the time and date.

List time zones

You can obtain a list of time zones from the device by running the following script from the UEM console:

Lists various time zones.

Any time zone from the generated list can be substituted for the $1 argument in the Set time zone custom script. This modified script can then be deployed to the device from the Hexnode console.

What happens at the device end?

Upon execution of the script to set time zone, the device’s time will be adjusted based on the configured time zone. In the “System Settings > General” under “Date & Time”, the time zone and the closest city will be blanked out. Users will not be able to edit them unless the “Set time zone automatically using your location” option is toggled on and off.

Notes:

  • Turning “Set time zone automatically using your location” on and off from the device will reset the time zone to the correct time zone based on the current location.
  • Enforcing the time zone on a device manually also adjusts the device clock based on the specified location.
  • 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