Changing Language Preference

fdechirico
New Contributor

Hello All

I am new to JSS and was wondering if there is a simple way to change the language preference?

What is the best way to push the policy?

Basically we want to enforce french OS on some maverick computers.

thanks
FD

17 REPLIES 17

justinworkman
Contributor

I don't know that much about changing localizations. But I have discovered if you run a script that does the following, you should get what you want.

defaults write /Library/Preferences/.GlobalPreferences AppleLanguages fr
defaults write /Users/*loggedinuser*/Library/Preferences/.GlobalPreferences AppleLanguages fr

You can either force a reboot or a ```
killall Finder
``` to see the changes.

At least this works on my stuff. Let me know how it goes. I'd be glad to keep working on a solution for this. It's interesting...

bentoms
Honored Contributor III
Honored Contributor III

Here's an old post I have on this; http://macmule.com/2011/03/02/setting-user-os-language-post-install-from-casper/

Never got around to scripting it, hope it helps.

justinworkman
Contributor

Duplicate

justinworkman
Contributor

bentoms, that post looks spot on. Based on the fiddling I've been doing, it should still work for Mavericks.

fdechirico
New Contributor

does the maverick i'm using composer with need to be the same build as the mavericks i'm pushing the policy out to?

justinworkman
Contributor

I think typically that's a "best practice." Having said that, I think that since the information is pretty much the same from 10.6 to 10.9, it shouldn't matter too much.

fdechirico
New Contributor

Hi Guys

So this is what im doing.

1) im on a maverick machine running composer. I run the command sudo languagesetup –langspec French , and /usr/bin/defaults write -g AppleLanguages "(fr)" so now my OS is french.

2) i then open up composer and go to user enviroment and choose Global Preference.

3) I then build a DMG and save it to my desktop. I copy the DMG to my JSS server with casper admin

4) I then create a policy to push to a test machine.

My goal is to push this so any user that logs into the OS is french,

Am i doing this right?
thanks

justinworkman
Contributor

Your workflow looks correct, but I think you'll also want to capture the plist at ~/Library/Preferences/.GlobalPreferences.plist.

franton
Valued Contributor III

@fdechirico Beware of OS X's new behaviour of caching preference files. Direct manipulation of the files by your method is no longer guaranteed to work.

Best way is the defaults writes command. That will force the OS to recache the changed plist after it's written to disk.

fdechirico
New Contributor

sorry i'm new to jss

how would i go about capturing ~/Library/Preferences/.GlobalPreferences.plist.?

justinworkman
Contributor

Based on what @franton said, I would say that you're best bet would be to have a script that runs on each machine doing the defaults write on ~/Library Preferences/.GlobalPreferences and /Library/Preferences/.GlobalPreferences.

bentoms
Honored Contributor III
Honored Contributor III

@justinworkman, that's why i deploy the Plists & imaging & use FEU & FUT's as they files are placed with the correct settings & you effectively bypass the CFPrefs issue

justinworkman
Contributor

Oh. I wasn't aware the preference files are being cached. Is that new in 10.9?

bentoms
Honored Contributor III
Honored Contributor III

justinworkman
Contributor

Interesting. I was running into this caching monster when researching this topic, but didn't even know it! I was trying to write a script using Plistbuddy to make the edits and they were getting overwritten and I couldn't figure out why. Now I know. Thanks @bentoms.

fdechirico
New Contributor

Hi

Would anyone know how to create a script with the following commands then

defaults write /Library/Preferences/.GlobalPreferences AppleLanguages fr
defaults write /Users/loggedinuser/Library/Preferences/.GlobalPreferences AppleLanguages fr

I tried applescript but complains of syntax error

this is what i have
#!/bin/sh

defaults write /Library/Preferences/.GlobalPreferences AppleLanguages fr

defaults write /Users/loggedinuser/Library/Preferences/.GlobalPreferences AppleLanguages fr

thanks

jleomcdo
Contributor

Not sure if you are still looking for a script. Here is what I came up with to set the Regional Setting and also the keyboard input source.
(applescript) It will set the current logged in users preferences. (still working on trying to make these setting to be global.)
--Get properties for the computer based on computer name
set ComputerName to computer name of (system info)
set ComputerCountryCode to characters 1 thru 2 of ComputerName as string

--Change OS language
#do shell script ("defaults write -g AppleLanguages -array en es ja fr de it pt " & "'" & "pt-PT" & "'" & " nl sv nb da fi ru pl " & "'" & "zh-Hans" & "'" & " '" & "zh-Hant" & "'" & " ko ar cs hu tr")
--Change default System Language - Login Window
#do shell script ("languagesetup -langspec " & "'" & "English" & "'")
--Change user's format
#do shell script "defaults write -g AppleLocale en_US"
--Change Country
#do shell script "defaults write -g Country en_US"

--Configure locale. Default Language is "en" if not specified.
if ComputerCountryCode is "UK" then set LanguageCode to "en" set CountryCode to "GB" set Units to "Inches" set Metric to "false" set KeyboardInterger to 2 set KeyboardName to "British"
else if ComputerCountryCode is "MX" then set LanguageCode to "es" set CountryCode to "MX" set Units to "Centimeters" set Metric to "true" set KeyboardInterger to 8 set KeyboardName to "Spanish"
else if ComputerCountryCode is "IE" then set LanguageCode to "en" set CountryCode to "IE" set Units to "Centimeters" set Metric to "true" set KeyboardInterger to 500 set KeyboardName to "Irish Extended"
else set LanguageCode to "en" set CountryCode to "US" set Units to "Inches" set Metric to "false" set KeyboardInterger to 0 set KeyboardName to "U.S."
end if

--Set Locale of machine
do shell script "defaults write -g AppleLocale " & LanguageCode & "" & CountryCode
do shell script "defaults write -g Country " & LanguageCode & "
" & CountryCode
do shell script "defaults write -g AppleMeasurementUnits " & Units
do shell script "defaults write -g AppleMetricUnits -bool " & Metric

--Set Keyboard
try do shell script ("/usr/libexec/PlistBuddy -c " & "'" & "Delete AppleEnabledInputSources array" & "'" & " ~/Library/Preferences/com.apple.HIToolbox.plist") do shell script ("/usr/libexec/PlistBuddy -c " & "'" & "Delete AppleSelectedInputSources array" & "'" & " ~/Library/Preferences/com.apple.HIToolbox.plist")
end try

do shell script ("/usr/libexec/PlistBuddy -c " & "'" & "Add AppleEnabledInputSources array" & "'" & " ~/Library/Preferences/com.apple.HIToolbox.plist")
do shell script ("/usr/libexec/PlistBuddy -c " & "'" & "Add AppleEnabledInputSources:0 dict " & "'" & " ~/Library/Preferences/com.apple.HIToolbox.plist")
do shell script ("/usr/libexec/PlistBuddy -c " & "'" & "Add AppleEnabledInputSources:0:" & "'" & "InputSourceKind" & "'" & " string Keyboard Layout" & "'" & " ~/Library/Preferences/com.apple.HIToolbox.plist")
do shell script ("/usr/libexec/PlistBuddy -c " & "'" & "Add AppleEnabledInputSources:0:" & """ & "KeyboardLayout ID"" & " integer " & KeyboardInterger & "'" & " ~/Library/Preferences/com.apple.HIToolbox.plist")
do shell script ("/usr/libexec/PlistBuddy -c " & "'" & "Add AppleEnabledInputSources:0:" & """ & "KeyboardLayout Name"" & " string " & KeyboardName & "'" & " ~/Library/Preferences/com.apple.HIToolbox.plist")
do shell script ("/usr/libexec/PlistBuddy -c " & "'" & "Add AppleSelectedInputSources array" & "'" & " ~/Library/Preferences/com.apple.HIToolbox.plist")
do shell script ("/usr/libexec/PlistBuddy -c " & "'" & "Add AppleSelectedInputSources:0 dict " & "'" & " ~/Library/Preferences/com.apple.HIToolbox.plist")
do shell script ("/usr/libexec/PlistBuddy -c " & "'" & "Add AppleSelectedInputSources:0:" & "'" & "InputSourceKind" & "'" & " string Keyboard Layout" & "'" & " ~/Library/Preferences/com.apple.HIToolbox.plist")
do shell script ("/usr/libexec/PlistBuddy -c " & "'" & "Add AppleSelectedInputSources:0:" & """ & "KeyboardLayout ID"" & " integer " & KeyboardInterger & "'" & " ~/Library/Preferences/com.apple.HIToolbox.plist")
do shell script ("/usr/libexec/PlistBuddy -c " & "'" & "Add AppleSelectedInputSources:0:" & """ & "KeyboardLayout Name"" & " string " & KeyboardName & "'" & " ~/Library/Preferences/com.apple.HIToolbox.plist")