Skip to main content
Solved

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


Forum|alt.badge.img+3

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.

Best answer by cdev

AJPinto wrote:

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

  


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 original
Did this topic help you find an answer to your question?

10 replies

AJPinto
Forum|alt.badge.img+26
  • Legendary Contributor
  • 2710 replies
  • November 6, 2023

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
Forum|alt.badge.img+14
  • Contributor
  • 135 replies
  • Answer
  • November 6, 2023
AJPinto wrote:

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

  


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

Forum|alt.badge.img+3
  • Author
  • New Contributor
  • 4 replies
  • November 7, 2023
cdev wrote:

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 error


Forum|alt.badge.img+3
  • Author
  • New Contributor
  • 4 replies
  • November 7, 2023
Dhuhindhan wrote:

Hi @cdev , Tried running the script on macOS Sonoma but getting this error


is there something we need to change based on the OS


cdev
Forum|alt.badge.img+14
  • Contributor
  • 135 replies
  • November 7, 2023
Dhuhindhan wrote:

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.


Forum|alt.badge.img+3
  • Author
  • New Contributor
  • 4 replies
  • November 7, 2023

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


JevermannNG
Forum|alt.badge.img+8
  • Valued Contributor
  • 136 replies
  • September 23, 2024
Dhuhindhan wrote:

Hi @cdev , Tried running the script on macOS Sonoma but getting this error


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.


Forum|alt.badge.img+3
  • New Contributor
  • 2 replies
  • September 24, 2024
JevermannNG wrote:

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.


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
Forum|alt.badge.img
  • New Contributor
  • 1 reply
  • December 11, 2024
cdev wrote:

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

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


Forum|alt.badge.img+5
cdev wrote:

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.


Does this script prevent the user from disabling the automatic toggle?


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings