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
Set time zone
1 2 3 4 5 |
#!/bin/sh #!/usr/bin/env bash sudo systemsetup -settimezone $1 |
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”:
1 2 3 4 5 |
#!/bin/sh #!/usr/bin/env bash sudo systemsetup -settimezone 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.
1 |
/usr/sbin/systemsetup -setusingnetworktime on -setnetworktimeserver time.apple.com |
List time zones
You can obtain a list of time zones from the device by running the following script from the UEM console:
1 |
sudo systemsetup -listtimezones #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.