通过applescript获取当前登录用户的语言 [英] get language of currently logged in user via applescript

查看:32
本文介绍了通过applescript获取当前登录用户的语言的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获取当前登录用户的系统语言.线

I want to get the system language of the currently logged in user. The line

set lang to do shell script "defaults read NSGlobalDomain AppleLanguages"

返回一个字符串,看起来像

returns an string, which looks like

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

返回用户语言,但我怎样才能得到这个数组"的第一个?是否有可能将其解析为数组并获取其第一个值?

returns the users languages, but how can I get the first one of this 'array'? Is there a possibility to parse this as an array an get its first value?

推荐答案

有一个更直接的方法.Applescript 有一个命令系统信息",它返回许多关于当前用户的有用信息.试试这个看看...

There's a more direct method. Applescript has a command "system info" which returns a lot of useful information about the current user. Try this to see...

return system info

可以帮助您的信息是用户区域设置".这样您就可以轻松获得语言...

The information that will help you from that is "user locale". So you can get the language easily...

return user locale of (get system info)

在不同的用户上玩这个,看看它是否能满足你的需求.

Play around with this on different users and see if it gives you what you want.

这篇关于通过applescript获取当前登录用户的语言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆