Sunday, September 22, 2019

#1 2019-08-20 12:14:59 pm

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 3579

How to get the value of 'Apple Global Domain' AppleLocale

Hello

For years I check if I must use French messages or English ones in my scripts with this handler:

Applescript:

on parle_anglais()
   return (do shell script "defaults read 'Apple Global Domain' AppleLocale") does not start with "fr_"
end parle_anglais

true means : use English messages
false means : use French messages.
I'm wondering if I may do the same using ASObjC.

At this time, I may code :

Applescript:

use AppleScript version "2.4"
use framework "Foundation"
use scripting additions

set fixLocale to current application's NSLocale's currentLocale() --> <__NSCFLocale: 0x6000002c1960> 'fr_FR'}

set liveLocale to current application's NSLocale's autoupdatingCurrentLocale() --> (NSAutoLocale) Auto-updating Locale <NSAutoLocale: 0x60c000487440> [<__NSCFLocale: 0x6000002c1960>] 'fr_FR'}

But I found no way to grab the relevant info : 'fr_FR'

Any help welcome.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) mardi 20 aout 2019  20:14:06

Offline

 

#2 2019-08-20 12:26:00 pm

StefanK
Member
From:: St. Gallen, Switzerland
Registered: 2006-10-21
Posts: 11598
Website

Re: How to get the value of 'Apple Global Domain' AppleLocale

NSLocale has a property localeIdentifier

Applescript:

set fixLocale to current application's NSLocale's currentLocale()'s localeIdentifier() as text

or even languageCode

Applescript:

set fixLocale to current application's NSLocale's currentLocale()'s languageCode() as text

to get only the first part of the identifier

It's always worth it to read the documentation of a class

Last edited by StefanK (2019-08-20 12:30:15 pm)


regards

Stefan

Offline

 

#3 2019-08-20 01:07:05 pm

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 3579

Re: How to get the value of 'Apple Global Domain' AppleLocale

Thank you Stefan.

I missed that.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) mardi 20 aout 2019  21:06:59

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)