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 09-23-2024 02:53 AM
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.
Posted on 09-23-2024 08:46 PM
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.
Posted on 11-07-2023 10:52 AM
hi @cdev gotcha!!! the restart does the trick, Thanks!!!!!!