Auto change of time according to timezone

sk25
Contributor

Guys,

We have a requirements that customer would like want to get the change time change automatically as soon as end user travelled to some other location or region. Kindly help me with the shell script it would be much appreciated. Thanks.

2 REPLIES 2

sdagley
Esteemed Contributor II

@sk25 You need to have Location Services and automatically set time zone enabled on a Mac for it to automatically adjust time. The following script will set that up (you'll want to restart the Mac to ensure the changes take effect):

#!/bin/sh

uuid=$(/usr/sbin/system_profiler SPHardwareDataType | grep "Hardware UUID" | cut -c22-57)
/usr/bin/defaults write /var/db/locationd/Library/Preferences/ByHost/com.apple.locationd.$uuid LocationServicesEnabled -int 1

/usr/bin/defaults write /Library/Preferences/com.apple.timezone.auto Active -bool YES
/usr/bin/defaults write /private/var/db/timed/Library/Preferences/com.apple.timed.plist TMAutomaticTimeOnlyEnabled -bool YES
/usr/bin/defaults write /private/var/db/timed/Library/Preferences/com.apple.timed.plist TMAutomaticTimeZoneEnabled -bool YES
/usr/sbin/systemsetup -setusingnetworktime on

exit 0

 

Capside
New Contributor

@sdagley for information, you can use the following commands to take changes into account immediately

/bin/launchctl kickstart -k system/com.apple.locationd
/bin/launchctl kickstart -k system/com.apple.timed