Posted on 12-29-2012 06:47 AM
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
Solved! Go to Solution.
Posted on 01-02-2013 06:06 AM
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
Posted on 12-29-2012 12:13 PM
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/
Posted on 12-30-2012 10:41 AM
#!/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 .
Posted on 01-02-2013 04:08 AM
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
Posted on 01-02-2013 06:06 AM
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
Posted on 01-02-2013 06:42 AM
Hello again!
@stevewood, many thanks, you were right.
Now I can say "it works"!
Ciao
Carlo
Posted on 04-23-2020 08:07 AM
@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.
Posted on 04-15-2021 11:06 AM
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
Posted on 01-12-2022 02:01 PM
@matheo_lm , Thanks. Much better. I'll use that as it's been spitting out garbage and I've not fixed it.