When you set up your Mac for the first time, Setup Assistant will ask you for your preferred language and region. In the graphical user interface (GUI), you can later find (and change) these settings in System Settings > General > Language & Region. But what if you want to find them in the command-line interface (CLI)?
You might think that if you run the locale
command that that would give you the selected locale, but if you run that, select a different language and/or region, and then run locale
again, you’ll see the output remains unchanged.
The actual command you want is either defaults read -g AppleLocale
or defaults read .GlobalPreferences AppleLocale
or defaults read ~/Library/Preferences/.GlobalPreferences AppleLocale
.
It does seem, regardless of what language and region you select and regardless of what country you’re in when you set up the Mac, that the root-owned preference is just en_US
. So if you run /usr/bin/defaults read -g AppleLocale
as root (as Munki or Jamf would run, for example), you will probably get back en_US
.
If you aren’t familiar with how to get the current user instead of root from a root-run script, here’s a quick primer.
You could, for instance, get the logged-in user’s language and region like this:
loggedInUser=$(stat -f %Su /dev/console)
/usr/bin/su -l $loggedInUser -c '/usr/bin/defaults read -g AppleLocale'
One other thing to consider when looking at the output is that the form won’t always be language_REGION exactly. If someone selects a different region, they may get this sort of prompt:
Depending on what you select, you may get the AppleLocale returned back as something like en_PH@rg=gbzzzz
instead of something like en_PH
. So that’s basically, in this example, English for the Philippines with UK English vs. English for the Philippines with US English. That potential output format is something to be mindful of, in case you’re using sed
, awk
, or some other tool to process the output.
Leave a Reply