Posted on 11-06-2023 05:43 AM
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.
Solved! Go to Solution.
Posted on 11-06-2023 11:00 AM
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
Posted on 11-07-2023 09:27 AM
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.
Posted on 11-06-2023 06:44 AM
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
Posted on 11-06-2023 11:00 AM
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
Posted on 11-07-2023 02:37 AM
Hi @cdev , Tried running the script on macOS Sonoma but getting this error
Posted on 11-07-2023 02:38 AM
is there something we need to change based on the OS
Posted on 11-07-2023 09:27 AM
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.
Posted on 11-07-2023 10:52 AM
hi @cdev gotcha!!! the restart does the trick, Thanks!!!!!!