how to enable the set time zone automatically using your current location radio button on system set

Dhuhindhan
New Contributor

Hi, I want to enable set time zone automatically using your current location radio button on system settings for all my org Mac on bulk. How do we get it, I want all the Mac date and time settings to be like it is on this image.

Screenshot 2023-11-06 at 8.58.39 AM.png

2 ACCEPTED SOLUTIONS

cdev
Contributor III

Give this a shot:

 

#!/bin/bash

uuid=$("/usr/sbin/system_profiler" SPHardwareDataType | grep "Hardware UUID" | awk '{ print $3 }')
timedPrefs="/private/var/db/timed/Library/Preferences/com.apple.timed.plist"
dateTimePrefs="/private/var/db/timed/Library/Preferences/com.apple.preferences.datetime.plist"
locationPrefs="/private/var/db/locationd/Library/Preferences/ByHost/com.apple.locationd.${uuid}"
byHostPath="/var/db/locationd/Library/Preferences/ByHost/com.apple.locationd"

# Set preferences.
echo "Ensuring location services are enabled"
sudo -u "_locationd" /usr/bin/defaults -currentHost write "$locationPrefs" LocationServicesEnabled -int 1
sudo defaults write "${byHostPath}" LocationServicesEnabled -int 1
/usr/sbin/chown "_locationd:_locationd" "$locationPrefs"

echo "Configuring automatic time"
/usr/bin/defaults write "$timedPrefs" TMAutomaticTimeZoneEnabled -bool YES
/usr/bin/defaults write "$timedPrefs" TMAutomaticTimeOnlyEnabled -bool YES
/usr/bin/defaults write "$dateTimePrefs" timezoneset -bool YES
/usr/sbin/chown "_timed:_timed" "$timedPrefs" "$dateTimePrefs"

exit 0

View solution in original post

I’ve had good luck with that script as is running on Sonoma Macs, including enabling location services. Sometimes it’s taken a reboot for the settings to fully apply, but most of my runs have worked within 2 minutes.

View solution in original post

6 REPLIES 6

AJPinto
Honored Contributor II

This would require location services which you cannot force enable for a user. I don't think what you are asking is possible. However, the time zone can be set with a script. You can work something out in JAMF to set time zones with a policy.

 

#!/bin/sh

#--------------------------------------------------------
# Set the Mac timezone & timeservers
#--------------------------------------------------------

# Set the timezone
systemsetup -settimezone "$4"

# Set the timezone to regions internal time server
/usr/sbin/systemsetup -setnetworktimeserver 10.255.216.19

# The below command will list all available timezones
# systemsetup -listtimezones

  

cdev
Contributor III

Give this a shot:

 

#!/bin/bash

uuid=$("/usr/sbin/system_profiler" SPHardwareDataType | grep "Hardware UUID" | awk '{ print $3 }')
timedPrefs="/private/var/db/timed/Library/Preferences/com.apple.timed.plist"
dateTimePrefs="/private/var/db/timed/Library/Preferences/com.apple.preferences.datetime.plist"
locationPrefs="/private/var/db/locationd/Library/Preferences/ByHost/com.apple.locationd.${uuid}"
byHostPath="/var/db/locationd/Library/Preferences/ByHost/com.apple.locationd"

# Set preferences.
echo "Ensuring location services are enabled"
sudo -u "_locationd" /usr/bin/defaults -currentHost write "$locationPrefs" LocationServicesEnabled -int 1
sudo defaults write "${byHostPath}" LocationServicesEnabled -int 1
/usr/sbin/chown "_locationd:_locationd" "$locationPrefs"

echo "Configuring automatic time"
/usr/bin/defaults write "$timedPrefs" TMAutomaticTimeZoneEnabled -bool YES
/usr/bin/defaults write "$timedPrefs" TMAutomaticTimeOnlyEnabled -bool YES
/usr/bin/defaults write "$dateTimePrefs" timezoneset -bool YES
/usr/sbin/chown "_timed:_timed" "$timedPrefs" "$dateTimePrefs"

exit 0

Hi @cdev , Tried running the script on macOS Sonoma but getting this errorScreenshot 2023-11-07 at 11.36.00 AM.png

is there something we need to change based on the OS

I’ve had good luck with that script as is running on Sonoma Macs, including enabling location services. Sometimes it’s taken a reboot for the settings to fully apply, but most of my runs have worked within 2 minutes.

Dhuhindhan
New Contributor

hi @cdev gotcha!!! the restart does the trick, Thanks!!!!!!