Change the OSX system language in a script

3

1

Manually I just go into the system preferences, change the language ordering, and restart my app so it starts up in the default system language. Then I can run automated tests with the app running in that language.

In the command line, there is a built-in OSX utility languagesetup but this requires sudo and it has to prompt for the new language (i.e. there is no obvious command line option).

I don't know AppleScript well enough to use that but I would be open to using it.

travis1097

Posted 2013-09-09T19:55:43.567

Reputation: 237

Answers

4

You can open an application using a different language by adding an -AppleLanguages option:

/Applications/Calendar.app/Contents/MacOS/Calendar -AppleLanguages '(de)'

Another option is to add an AppleLanguages array to the property list of the application:

defaults write -app Calendar AppleLanguages -array de; open -a Calendar

languagesetup just changes the first item in the AppleLanguages array in /Library/Preferences/.GlobalPreferences.plist.

Lri

Posted 2013-09-09T19:55:43.567

Reputation: 34 501

Launching the application with that flag does exactly what I want. – travis1097 – 2013-09-10T17:16:07.143

1

There's no need to change the system default language (for most apps, at least). System Preferences » Language & Text doesn't change the system default language anyway, it's just configuration of your user profile.


The following script writes the list of preferred languages (first German, then English):

defaults write -g AppleLanguages -array de en

Run this, then open your application. Add or remove language IDs as needed.

To list your current language configuration:

$ defaults read -g AppleLanguages
(
    en,
    de
)

Daniel Beck

Posted 2013-09-09T19:55:43.567

Reputation: 98 421

Daniel is right but you might want to "defaults read" the array first and copy all the language codes first so you don't have go back and check each one (if you're looking to test all of them). His sample code will only show english and german in the pref pane top level after written. I am using his settings suggestion in a script to periodically reset the default language to English for students in an English immersion program. (of course add - killall Finder) Thanks, Daniel. – None – 2013-09-20T12:39:51.893