Extension attribute to gather OS main language, is it possible?

carlo_anselmi
Contributor III

Hello and happy holidays everyone!
I would like to ask your help to understand if there's a way to gather the main OS language set at user level.
We have a mixed environment with two languages being used (Italian and English) with only some single-language applications installed accordingly (Office 2011 and Adobe's).
Knowing which language is being used would be very helpful to create smartgroups and deploy apps/updates (such as Office 14.2.5) where there are separate updates for each country.
Many thanks for your support!
Ciao
Carlo

1 ACCEPTED SOLUTION

stevewood
Honored Contributor II
Honored Contributor II

Make sure you are giving the full path to the .GlobalPreferences file. I tried your command on my machine and it did not work, until I added /Library/Preferences in front of .GlobalPreferences:

#!/bin/sh

PRIMLOCALE=$( defaults read /Library/Preferences/.GlobalPreferences AppleLanguages | tr -d [:space:] | cut -c2-3 )
echo "<result>$PRIMLOCALE</result>"

exit 0

View solution in original post

8 REPLIES 8

bentoms
Release Candidate Programs Tester

Hi Carlo,

I've not done what you've wanted.

But i hope the following post should show where the plists containing this info are kept. http://macmule.com/2011/03/02/setting-user-os-language-post-install-from-casper/

franton
Valued Contributor III
#!/bin/sh

# Example script to see retrieve primary locale on a target mac.
# Script will return the info as an extension attribute.
# Author: r.purves@arts.ac.uk
# Version 1.0 : 30-12-2012 - Initial Version

PRIMLOCALE=$( defaults read /Library/Preferences/.GlobalPreferences.plist AppleLocale )
echo "<result>${PRIMLOCALE}</result>"

exit 0

This is very basic and may not be looking at the right place for your needs. Consult bentoms link and you should be able to modify my very rough script for use. Currently this will return any locale so you should be looking for en_US , en_UK or it_IT .

carlo_anselmi
Contributor III

Hello and Happy New Year,
many thanks for your suggestions. I found something with Google and changed the script to

#!/bin/sh PRIMLOCALE=$( defaults read .GlobalPreferences AppleLanguages | tr -d [:space:] | cut -c2-3 ) echo "<result>$PRIMLOCALE</result>" exit 0

This works fine on my Mac if run as script from the Terminal but when used as string to populate the extension attribute it shows nothing within the inventory report :-(
Any help would be greatly appreciated!
Ciao
Carlo

stevewood
Honored Contributor II
Honored Contributor II

Make sure you are giving the full path to the .GlobalPreferences file. I tried your command on my machine and it did not work, until I added /Library/Preferences in front of .GlobalPreferences:

#!/bin/sh

PRIMLOCALE=$( defaults read /Library/Preferences/.GlobalPreferences AppleLanguages | tr -d [:space:] | cut -c2-3 )
echo "<result>$PRIMLOCALE</result>"

exit 0

carlo_anselmi
Contributor III

Hello again!
@stevewood, many thanks, you were right.
Now I can say "it works"!
Ciao
Carlo

ScottyBeach
Contributor

@stevewood Thanks very much for this. I had to adjust to "cut -c3-7" to get it to return the full region-language like en-CA for Canada English or fr-FR for France French. It's been a few years so maybe the OS stores it differently now.

matheo_lm
New Contributor

Made another modification to just get the first TWO lowercase letters of the main language. The script above returned ")" in Mojave and some Big Sur devices during testing.

#!/bin/sh

PRIMLOCALE=$(defaults read /Library/Preferences/.GlobalPreferences AppleLanguages |  sed 's/[^a-z]//g' | xargs | cut -c1-2)
echo "<result>$PRIMLOCALE</result>"

exit 0

ScottyBeach
Contributor

@matheo_lm , Thanks. Much better. I'll use that as it's been spitting out garbage and I've not fixed it.