AppleLocale doesn't exist in .GlobalPreferences.plist

The following command is executed in the application we are developing.


osLocale = `sudo -u $ USER defaults read -g AppleLocale`


In many Mac environments, locale information can be obtained, but in some Mac (10.13, 10.14) environments, "does not exist" is returned and locale information cannot be obtained.

I found that the AppleLocale key doesn't exist in .GlobalPreferences.plist in the environment.


Why doesn't the AppleLocale key exist in the .GlobalPreferences.plist file?

Is the environment where the AppleLocale key doesn't exist in the .GlobalPreferences.plist file normal?

Is there a way to set the AppleLocale key in the .GlobalPreferences.plist file?

Replies

What are you trying to do here?

In general, running framework code (for example,

defaults
, which is based on Foundation) using
sudo -u
won’t end well because
sudo -u
only switches the traditional UNIX execution context, it does not switch macOS specific stuff (see the Execution Contexts section of Technote 2083 Daemons and Agents for more background on this). Framework code tends to rely on macOS context values, and so misbehaves in this split context.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Thank you for your reply.


Please don't worry about the command.


Could you answer about the following?


>I found that the AppleLocale key doesn't exist in .GlobalPreferences.plist in the environment.


>Why doesn't the AppleLocale key exist in the .GlobalPreferences.plist file?

>Is the environment where the AppleLocale key doesn't exist in the .GlobalPreferences.plist file normal?

>Is there a way to set the AppleLocale key in the .GlobalPreferences.plist file?

Please don't worry about the command.

Ah, um, the command is kinda important. If, on one of the problematic machines, you log in as the target user and run an app that reads

AppleLocale
using
NSUserDefaults
, do you get a reasonable value?

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

In the application we are developing, unix command in shell script is executed.

We cannnot change the program language, so cannot use

NSUserDefaults.

Is there other solutions to get AppleLocale?

Is there other commands which can be executed in shell script?


Could you answer about the following?

>Is the environment where the AppleLocale key doesn't exist in the .GlobalPreferences.plist file normal?


Desired delivery date: 1/3 JST

We cannnot change the program language, so cannot use NSUserDefaults.

I think you missed a couple of key points about my suggestion:

  • In addition to calling

    NSUserDefaults
    , I suggested logging in as that user. My primary concern here is your user switching via
    sudo
    .
  • Also, you don’t necessarily have to deploy this way. I posted this suggestion as a diagnostic test.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"