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

9 REPLIES 9

AJPinto
Honored Contributor III

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.

I get the same error running the script on macOS 15.0

We are looking for a similar script that sets the Time Zone for out Virtual Machines because for some unknown reason, they dont fetch the correct zone during Enrollment.

Leadehh
New Contributor II

Hi Jevermann,

We use the following:

#!/bin/zsh
#
# Daniel Angeloni 2024
#
# Sets timezone and region
#
timezone="Australia/Sydney"
region="AU"

# Set the timezone
systemsetup -settimezone "$timezone"
if [ $? -eq 0 ]; then
  echo "Timezone set to $timezone"
else
  echo "Failed to set timezone" >&2
  exit 1
fi

# Set the region
defaults write NSGlobalDomain AppleLocal en_"$region"
if [ $? -eq 0 ]; then
  echo "Region set to $region"
else
  echo "Failed to set AppleLocal" >&2
  exit 1
fi

defaults write NSGlobalDomain AppleLocale en_"$region"
if [ $? -eq 0 ]; then
  echo "Region set to $region"
else
  echo "Failed to set AppleLocale" >&2
  exit 1
fi

defaults write NSGlobalDomain OSLocale en_"$region"
if [ $? -eq 0 ]; then
  echo "Region set to $region"
else
  echo "Failed to set OSLocale" >&2
  exit 1
fi

defaults write NSGlobalDomain region "$region"
if [ $? -eq 0 ]; then
  echo "Region set to $region"
else
  echo "Failed to set region" >&2
  exit 1
fi

defaults write com.apple.dock region "$region"
if [ $? -eq 0 ]; then
  echo "Region set to $region"
else
  echo "Failed to set region" >&2
  exit 1
fi

defaults write NSGlobalDomain loc en_GB:"$region"
if [ $? -eq 0 ]; then
  echo "Region set to $region"
else
  echo "Failed to set loc" >&2
  exit 1
fi


# Apply the changes

echo "Timezone and region settings applied successfully."
killall SystemUIServer

exit 0

 

Let us know how you go.

Hamish.

Aronjlove
New Contributor

This script still works on 15.2 as of the date of this post. Thanks!

Dhuhindhan
New Contributor

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