Skip to content

Instantly share code, notes, and snippets.

@ushuz
Last active August 5, 2023 05:58
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ushuz/4f8c2771b295330b23154acfc00795b3 to your computer and use it in GitHub Desktop.
Save ushuz/4f8c2771b295330b23154acfc00795b3 to your computer and use it in GitHub Desktop.
Fix macOS global "Country" setting
# view gloabl prefs in json
# plutil -convert json -o - -- /Library/Preferences/.GlobalPreferences.plist | python -m json.tool
import CoreFoundation as cf
# get current Country
cf.CFPreferencesCopyValue('Country', cf.kCFPreferencesAnyApplication, cf.kCFPreferencesAnyUser, cf.kCFPreferencesAnyHost)
# set Country
cf.CFPreferencesSetValue('Country', 'TW', cf.kCFPreferencesAnyApplication, cf.kCFPreferencesAnyUser, cf.kCFPreferencesAnyHost)
# persist changes
cf.CFPreferencesSynchronize(cf.kCFPreferencesAnyApplication, cf.kCFPreferencesAnyUser, cf.kCFPreferencesAnyHost)
# it's a lot easier to use 'defaults' to change the global .plist
#
# credit: @ShallJaiden in comments
#
sudo defaults write /Library/Preferences/.GlobalPreferences.plist Country -string "TW"
@Eric-Guo
Copy link

Need brew unlink python first if install the brew version before

@ushuz
Copy link
Author

ushuz commented Jul 16, 2020

Need brew unlink python first if install the brew version before

Or, you can always use /usr/bin/python

@ShallJaiden
Copy link

this doesn't work for me. I just simply run sudo defaults write /Library/Preferences/.GlobalPreferences.plist Country -string "TW"
that works for me

@ushuz
Copy link
Author

ushuz commented Sep 13, 2021

this doesn't work for me. I just simply run sudo defaults write /Library/Preferences/.GlobalPreferences.plist Country -string "TW"
that works for me

Thanks for sharing, that's far better. I'll incorporate it into the script for future visitors.

@robcholz
Copy link

Thank you. This has fixed the problem that bothers me for a long time!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment