Skip to content

Instantly share code, notes, and snippets.

@NikKovIos
Last active February 11, 2023 10:52
Show Gist options
  • Save NikKovIos/0d59251e0208c08c3c83d97ac69bc0ac to your computer and use it in GitHub Desktop.
Save NikKovIos/0d59251e0208c08c3c83d97ac69bc0ac to your computer and use it in GitHub Desktop.
Xcode Save Preferences Ruby script. Save and cache key bindings, color theme, snippets and so on. Just copy to text file, correct text in <> and do the chmod 700.
#!/bin/bash
modelNumber=$(/usr/sbin/ioreg -l | awk '/product-name/ { split($0, line, "\""); printf("%s\n", line[4]); }')
now=`date +%d-%m-%Y_%H-%M`
destinationFolder="Xcode($now)-$modelNumber"
target="/Users/<yourUser>/Library/Developer/Xcode/UserData"
destination="<where to place>/$destinationFolder"
userDataFolderName="UserData"
libraryPreferencesTarget="/Users/<yourUser>/Library/Preferences"
libraryPreferencesFolderName="Preferences"
echo "Creating a directory $destination"
mkdir -p $destination
echo "Creating a directory UserData"
mkdir -pv ${destination}/${userDataFolderName}
echo "Creating a directory Preferences"
mkdir -pv ${destination}/${libraryPreferencesFolderName}
echo "copying CodeSnippets"
cp -r ${target}/CodeSnippets ${destination}/${userDataFolderName}
echo "copying FontAndColorThemes"
cp -r ${target}/FontAndColorThemes ${destination}/${userDataFolderName}
echo "copying KeyBindings"
cp -r ${target}/KeyBindings ${destination}/${userDataFolderName}
echo "copying Preferences"
cp ${libraryPreferencesTarget}/com.apple.preferences.extensions.XcodeSourceEditor.plist ${destination}/${libraryPreferencesFolderName}
cp ${libraryPreferencesTarget}/com.apple.dt.xcodebuild.plist ${destination}/${libraryPreferencesFolderName}
$SHELL
# then do in terminal:
# chmod 700 <where to place>/copy-xcode-prefs-script
# in order to run script with double click
# Author: @NikeKov
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment