Skip to content

Instantly share code, notes, and snippets.

@rtrouton
Forked from pudquick/autotimezone.py
Created August 26, 2016 16:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rtrouton/c4989875f07f3f3b1a585aca28369e6c to your computer and use it in GitHub Desktop.
Save rtrouton/c4989875f07f3f3b1a585aca28369e6c 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
# (Generally this means wifi enabled on your device and network stack is up)
#
# Note: When this code exits, it will generate an error message - this is to be expected!
# Error will look like:
# Python[3056:158489] PyObjC: Exception during dealloc of proxy: Cannot remove an observer <TimeZonePref 0x7f846b4b6710>
# for the key path "enabled" from <ATZAdminPrefererences 0x7f846b502a30> because it is not registered as an observer.
#
# This is because we're cheating with the initialization of a TimeZonePref class to get cheap access to
# startAutoTimeZoneDaemon, bypassing proper event monitoring attachment.
#
# This error is ok / harmless.
from Foundation import NSBundle
TZPP = NSBundle.bundleWithPath_("/System/Library/PreferencePanes/DateAndTime.prefPane/Contents/Resources/TimeZone.prefPane")
TimeZonePref = TZPP.classNamed_('TimeZonePref')
pref = TimeZonePref.alloc().init()
result = pref._startAutoTimeZoneDaemon_(0x1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment