Posted on 05-24-2016 09:16 AM
Hi JAMF Nation
I've seen a lot of threads, websites and blogs but nobody could give me a clear answer. I would like to set following:
Amsys was almost there with this first boot script: https://github.com/amsysuk/public_scripts/blob/master/first_boot/10.10_firstBoot.sh
I created this script so far:
#!/bin/sh
# Set keyboard layout, region and language (globally, per user and in user template)
PLBUDDY=/usr/libexec/PlistBuddy
KEYBOARDNAME="Swiss German"
KEYBOARDLAYOUTID="19"
LANG="de"
REGION="de_DE"
update_kdb_layout() {
${PLBUDDY} -c "Delete :AppleCurrentKeyboardLayoutInputSourceID" "${1}" &>/dev/null
if [ ${?} -eq 0 ]
then
${PLBUDDY} -c "Add :AppleCurrentKeyboardLayoutInputSourceID string com.apple.keylayout.${KEYBOARDNAME}" "${1}"
fi
for SOURCE in AppleDefaultAsciiInputSource AppleCurrentAsciiInputSource AppleCurrentInputSource AppleEnabledInputSources AppleSelectedInputSources
do
${PLBUDDY} -c "Delete :${SOURCE}" "${1}" &>/dev/null
if [ ${?} -eq 0 ]
then
${PLBUDDY} -c "Add :${SOURCE} array" "${1}"
${PLBUDDY} -c "Add :${SOURCE}:0 dict" "${1}"
${PLBUDDY} -c "Add :${SOURCE}:0:InputSourceKind string 'Keyboard Layout'" "${1}"
${PLBUDDY} -c "Add :${SOURCE}:0:KeyboardLayout ID integer ${KEYBOARDLAYOUTID}" "${1}"
${PLBUDDY} -c "Add :${SOURCE}:0:KeyboardLayout Name string '${KEYBOARDNAME}'" "${1}"
fi
done
}
update_language() {
${PLBUDDY} -c "Delete :AppleLanguages" "${1}" &>/dev/null
if [ ${?} -eq 0 ]
then
${PLBUDDY} -c "Add :AppleLanguages array" "${1}"
${PLBUDDY} -c "Add :AppleLanguages:0 string '${LANG}'" "${1}"
fi
}
update_region() {
${PLBUDDY} -c "Delete :AppleLocale" "${1}" &>/dev/null
${PLBUDDY} -c "Add :AppleLocale string ${REGION}" "${1}" &>/dev/null
${PLBUDDY} -c "Delete :Country" "${1}" &>/dev/null
${PLBUDDY} -c "Add :Country string ${REGION:3:2}" "${1}" &>/dev/null
}
update_kdb_layout "/Library/Preferences/com.apple.HIToolbox.plist" "${KEYBOARDNAME}" "${KEYBOARDLAYOUTID}"
for HOME in /Users/*
do
if [ -d "${HOME}"/Library/Preferences ]
then
cd "${HOME}"/Library/Preferences
HITOOLBOX_FILES=`find . -name "com.apple.HIToolbox.*plist"`
for HITOOLBOX_FILE in ${HITOOLBOX_FILES}
do
update_kdb_layout "${HITOOLBOX_FILE}" "${KEYBOARDNAME}" "${KEYBOARDLAYOUTID}"
done
fi
done
for HOME in "/System/Library/User Template"/*
do
if [ -d "${HOME}"/Library/Preferences ]
then
cd "${HOME}"/Library/Preferences
HITOOLBOX_FILES=`find . -name "com.apple.HIToolbox.*plist"`
for HITOOLBOX_FILE in ${HITOOLBOX_FILES}
do
update_kdb_layout "${HITOOLBOX_FILE}" "${KEYBOARDNAME}" "${KEYBOARDLAYOUTID}"
done
fi
done
/usr/sbin/languagesetup -langspec "${LANG}"
for HOME in /Users/*
do
if [ -d "${HOME}"/Library/Preferences ]
then
cd "${HOME}"/Library/Preferences
GLOBALPREFERENCES_FILES=`find . -name ".GlobalPreferences.*plist"`
for GLOBALPREFERENCES_FILE in ${GLOBALPREFERENCES_FILES}
do
update_language "${GLOBALPREFERENCES_FILE}" "${LANG}"
done
fi
done
for HOME in "/System/Library/User Template"/*
do
if [ -d "${HOME}"/Library/Preferences ]
then
cd "${HOME}"/Library/Preferences
GLOBALPREFERENCES_FILES=`find . -name ".GlobalPreferences.*plist"`
for GLOBALPREFERENCES_FILE in ${GLOBALPREFERENCES_FILES}
do
update_language "${GLOBALPREFERENCES_FILE}" "${LANG}"
done
fi
done
update_region "/Library/Preferences/.GlobalPreferences.plist" "${REGION}"
for HOME in /Users/*
do
if [ -d "${HOME}"/Library/Preferences ]
then
cd "${HOME}"/Library/Preferences
GLOBALPREFERENCES_FILES=`find . -name ".GlobalPreferences.*plist"`
for GLOBALPREFERENCES_FILE in ${GLOBALPREFERENCES_FILES}
do
update_region "${GLOBALPREFERENCES_FILE}" "${REGION}"
done
fi
done
for HOME in "/System/Library/User Template"/*
do
if [ -d "${HOME}"/Library/Preferences ]
then
cd "${HOME}"/Library/Preferences
GLOBALPREFERENCES_FILES=`find . -name ".GlobalPreferences.*plist"`
for GLOBALPREFERENCES_FILE in ${GLOBALPREFERENCES_FILES}
do
update_region "${GLOBALPREFERENCES_FILE}" "${REGION}"
done
fi
done
exit 0
I tested this script multiple times. I changed everything (System Language, User Language, User Template Language, User Keyboard Layout, User Template Keyboard Layout, User Region, User Template Region) on a 10.11 vanilla machine. Then ran this script to check if everything is set back. But just following works:
Does anybody have a solid script which could reset everything back to the desired localisation?
Thanks for your help!