-
-
Save rtrouton/c4989875f07f3f3b1a585aca28369e6c to your computer and use it in GitHub Desktop.
Forcing automatic timezone discovery with pyobjc on OS X
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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