Created
March 3, 2023 10:20
-
-
Save matiaskorhonen/8cb649f47be4aee6caa96971ce0ed212 to your computer and use it in GitHub Desktop.
A hacked together script to change iOS simulator languages and locales. Use at your own peril.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -e -o pipefail | |
checkRequirements() { | |
requiredCommands=("jq" "xargs" "xcrun") | |
for cmd in "${requiredCommands[@]}"; do | |
if ! command -v "$cmd" &> /dev/null | |
then | |
echo "$cmd could not be found" | |
exit 1 | |
fi | |
done | |
} | |
simulatorUdids() { | |
xcrun simctl list devices available --json | jq -r ".devices | flatten | .[].udid" | |
} | |
changeLocale () { | |
local UDID="${1}" | |
local LANGUAGES=("en-US" "fi-US") | |
local LOCALE="en_US" | |
local KEYBOARDS=("en_US@sw=QWERTY;hw=Automatic" "emoji@sw=Emoji" "fi_FI@sw=QWERTY-Swedish-Finnish;hw=Automatic") | |
local PREFERENCES="$HOME/Library/Developer/CoreSimulator/Devices/$UDID/data/Library/Preferences/.GlobalPreferences.plist" | |
local DEFAULTS="$HOME/Library/Developer/CoreSimulator/Devices/$UDID/data/Library/Preferences/.GlobalDefaults.plist" | |
if [[ -f "$PREFERENCES" ]]; then | |
echo "Found: $PREFERENCES" | |
# plutil -p "$PREFERENCES" | |
plutil -replace AppleLocale -string "$LOCALE" "$PREFERENCES" | |
plutil -replace AppleLanguages -json "$(jq -c -n '$ARGS.positional' --args "${LANGUAGES[@]}")" "$PREFERENCES" | |
plutil -replace AppleKeyboards -json "$(jq -c -n '$ARGS.positional' --args "${KEYBOARDS[@]}")" "$PREFERENCES" | |
elif [[ -f "$DEFAULTS" ]]; then | |
echo "Found: $DEFAULTS" | |
plutil -replace AppleLocale -string "$LOCALE" "$DEFAULTS" | |
plutil -replace AppleLanguages -json "$(jq -c -n '$ARGS.positional' --args "${LANGUAGES[@]}")" "$DEFAULTS" | |
else | |
echo "No plist for $UDID" | |
fi | |
} | |
checkRequirements | |
for udid in $(simulatorUdids); do | |
changeLocale "$udid" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment