9

I need to lauch iOS Simulator that uses specific language using command line. So I found that I can use

instruments -w <device>

and it is working great, I can set specific device. But how can I run simulator with specific language? I've tried adding

-AppleLanguages -AppleLocale

but there are some warnings:

Instruments Usage Error : Specified target process is invalid: -AppleLanguage

thanks!

3 Answers 3

7

To run your app must be installed and located (if not, will open default language)

Use this command to run your app with some language

xcrun simctl launch <deviceid> <appid> -AppleLanguages "(pt-BR)"

Sample:

xcodebuild -sdk iphonesimulator8.4 -arch i386 install DSTROOT=SomeFolder
xcrun instruments -w "iPhone 6 (8.4 Simulator)"
xcrun simctl install booted SomeFolder/Applications/YourApp.app
xcrun simctl launch booted com.yourdomain.yourapp -AppleLanguages "(pt-BR)"
0
7

The only way to launch iOS Simulator with specific language is to change contents of its .GlobalPreferences.plist file. Using xcrun tool will not work because it passess arguments to launched app and not changing language of simulator itself. Manipulation on .GlobalPreferences.plist is quite difficult because it is a binary plist file, so you cannot modify it as 'normal' xml. The easiest way to change its contents is to write simple Xcode Command Line Tool application, Foundation SDK has all tools needed to modify binary plists.

4
  • Just in addition to make someone's pain less hurt, the plist is located at ~/Library/Developer/CoreSimulator/Devices/${YOURID}/data/Library/Preferences since Xcode 8 I believe... (Changed path from previous Xcode versions) Correct me if I am wrong, but I think you can edit the plist file right now and leave the language key for your desired and delete the others and it will work. Also I believe you can just edit it for once with classic plist editor and you are okay... Commented Jun 25, 2018 at 8:25
  • 1
    This is a script I use to change locale in simulator before launching: gist.github.com/rumax/2470ec2fcc3ef84420542f049589407e See related article: itnext.io/…
    – mmccabe
    Commented Jul 15, 2019 at 1:36
  • @mmccabe any hint on why Simulator version 12.4 always changes the default keyboard settings even after setting it in GlobalPreferences.plist? Commented Mar 9, 2021 at 8:46
  • I ended up with a doing two things to end up with only one keyboard layout in the iOS Simulator. First as described in this answer I updated the GlobalPreferences.plist for that particular Simulator. Then I started the Simulator and before my actual UI Test I automated the Settings app of iOS to remove the keyboard which is automatically added by iOS Simulator once I start it. This way I ended up with only the keyboard layout I want to have. To get the simulator ID: itnext.io/… Commented Mar 24, 2021 at 8:19
0
export UDID=202B1006-C2DE-4CC6–8791–6EA4C3782XXX
plutil -replace AppleLocale -string "en_GB" ~/Library/Developer/CoreSimulator/Devices/$UDID/data/Library/Preferences/.GlobalPreferences.plist
xcrun simctl shutdown $UDID
xcrun simctl boot $UDID

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.