Skip to content

Instantly share code, notes, and snippets.

@pudquick
Last active February 11, 2020 15:55
Show Gist options
  • Save pudquick/ba235b7e90aafb9986158697a457a0d0 to your computer and use it in GitHub Desktop.
Save pudquick/ba235b7e90aafb9986158697a457a0d0 to your computer and use it in GitHub Desktop.
Forcing automatic timezone discovery with pyobjc on OS X
# Tested on 10.11
# Assumes your network is in a state to actually do the discovery and that you have
# automatic timezone discovery enabled in Date & Time and Location services enabled
# (Generally this means wifi enabled on your device and network stack is up)
# For enabling location services and auto, check Allister's work here:
# https://gist.github.com/arubdesu/b72585771a9f606ad800
from Foundation import NSBundle
TZPP = NSBundle.bundleWithPath_("/System/Library/PreferencePanes/DateAndTime.prefPane/Contents/Resources/TimeZone.prefPane")
TimeZonePref = TZPP.classNamed_('TimeZonePref')
ATZAdminPrefererences = TZPP.classNamed_('ATZAdminPrefererences')
atzap = ATZAdminPrefererences.defaultPreferences()
pref = TimeZonePref.alloc().init()
atzap.addObserver_forKeyPath_options_context_(pref, "enabled", 0, 0)
result = pref._startAutoTimeZoneDaemon_(0x1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment