Skip to content

Instantly share code, notes, and snippets.

@mokagio
Last active May 17, 2019 08:54
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save mokagio/b9a03486d46f8610ad99 to your computer and use it in GitHub Desktop.
Save mokagio/b9a03486d46f8610ad99 to your computer and use it in GitHub Desktop.
Script updating all plugins to be compatible with the latest Xcode and Xcode-beta
#!/bin/bash
#
# Updates all plug-ins to be compatible with the latest Xcode and Xcode-beta
#
plugins_location="~/Library/Application\ Support/Developer/Shared/Xcode/Plug-ins"
# Get Xcode's version
current_xcode_version="$(defaults read /Applications/Xcode.app/Contents/Info DVTPlugInCompatibilityUUID)"
# Get Xcode-beta's version, if any
if [ -e /Applications/Xcode-beta.app ]; then
current_xcode_beta_version="$(defaults read /Applications/Xcode-beta.app/Contents/Info DVTPlugInCompatibilityUUID)"
fi
# I haven't found a better way to get all the files in the plug-ins folder due
# to the space in the path, and my ignorance in shell scripting
for plugin in $(eval "ls $plugins_location")
do
echo -n "Updating $plugin..."
# Add the current Xcode's version to the array of compatible versions for
# the plugin
eval "defaults write $plugins_location/$plugin/Contents/Info DVTPlugInCompatibilityUUIDs -array-add $current_xcode_version"
# Do the same for Xcode-beta, if any
if [ $current_xcode_beta_version ]; then
eval "defaults write $plugins_location/$plugin/Contents/Info DVTPlugInCompatibilityUUIDs -array-add $current_xcode_beta_version"
fi
echo " ✅"
done
echo -e "\nAll done 👍 \nRemember restart Xcode to see your plugins."
@abigagli
Copy link

Nice, but you might probably want to simplify things a bit by:

  1. line 7: plugins_location ="$HOME/Library/Application Support/Developer/Shared/Xcode/Plug-ins" (No need to escape the space and $HOME gets expanded with no need to use eval)
  2. line 19: for plugin in "$plugins_location"/* (usually the most correct way to iterate over files in a directory)
  3. line 21: echo "Updating $plugin..." (Removed the -n option, since we now want newlines to be appended)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment