How to set a per-app locale in MacOS

Posted on October 20, 2023 with tags , . See the previous or next posts.

Where is the good MacOS documentation?

After spending ~20+ years with a Linux desktop, I’m trying to expand my desktop setup to include MacOS (well, desktop/laptop, I mean end user in general). And to my surprise, there’s no clear repository of MacOS info. Man pages yes, some StackOverflow, some Apple forums, but no canonical version. Or, I didn’t find it, please enlighten me 🙏

Another issue is that Apple apparently changes behaviour without clearly documenting it. In this specific case, the “region” part of the locale went through significant churn lately.

So, my goal:

  • keep system wide locale set to English default, with region Switzerland.
  • this region=CH means that date and number formats are also changed to CH version, e.g. one thousand + ½ is displayed as 1'000,50.
  • however, for a single app, I want a “standard” en_US locale, with the above number shown/formatted as 1,000.50; well, it’s more about parsing than formatting, but that’s irrelevant.

In Linux, this would simply mean running the app with the correct environment variables. But MacOS deprecated this a while back (it used to work). After reading what I could, the solution is quite easy, just not obvious:

% defaults read .GlobalPreferences|grep en_
    AKLastLocale = "en_CH";
    AppleLocale = "en_CH";
% defaults read -app FooBar
(has no AppleLocale key)
% defaults write -app FooBar AppleLocale en_US

And that’s it. Now, the defaults man page says the global-global is NSGlobalDomain, I don’t know where I got the .GlobalPreferences. But I only needed to know the key name (in this case, AppleLocale - of course it couldn’t be LC_ALL/LANG).

One day I’ll know MacOS better, but I try to learn more for 2+ years now, and it’s not a smooth ride. Old dog new tricks, right?