Know currently logged in user's language in ma

2019-09-07 06:43发布

问题:

what is the terminal command to know the user's language setting (language name is enough) in mac? Can you provide the shell script?

回答1:

You can get a list of the user's language preferences with defaults read NSGlobalDomain AppleLanguages. OS X will use the languages in decreasing order of preference (if the first one is not available in a particular app). On my machine:

$ defaults read NSGlobalDomain AppleLanguages
(
    en,
    ja,
    fr,
    de,
    es,
    it,
    pt,
    "pt-PT",
    nl,
    sv,
    nb,
    da,
    fi,
    ru,
    pl,
    "zh-Hans",
    "zh-Hant",
    ko,
    ar,
    cs,
    hu,
    tr
)

In bash, to get the first one (the primary UI language), you can slice off the first one with this (admittedly messy) script:

 langs=(`defaults read NSGlobalDomain AppleLanguages`)
 echo ${langs[1]/,/} # langs[0] is the open bracket


标签: macos shell