Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Small script to update Xcode's plug-ins' compatibility.
# You might need these
# require 'pathname'
# require 'fileutils'
# In case we want to also print the already updated plug-ins
DISPLAY_ALREADY_UPDATED = false
# For a bit of flavor
red = "\e[31m"
green = "\e[32m"
yellow = "\e[33m"
white = "\e[0m"
# Change our path
plugin_path = File.expand_path('~/Library/Application Support/Developer/Shared/Xcode/Plug-ins')
# Exit if the folder is not there
unless Dir.exists? plugin_path
puts "\n#{red}The plugin folder doesn't exist at path '#{plugin_path}'."
exit
end
Dir.chdir(plugin_path)
files = Dir['*.xcplugin']
# Exit if there are no plugins
if files.none?
puts "\n#{red}You have no plugins..."
exit
end
# Keep track of these for a nice output message
updated_plugins = 0
uptodate_plugins = 0
# Iterate through all plugins
files.each do |plugin|
# Lazy, lazy :)
xcode_uuid_key = 'DVTPlugInCompatibilityUUID'
plugin_uuids_key = xcode_uuid_key + 's'
# This path needs to escape the backslash, so we can't reuse the one above :(
plugin_plist = "~/Library/Application\\ Support/Developer/Shared/Xcode/Plug-ins/#{plugin}/Contents/Info.plist"
plugin_uuids = `defaults read #{plugin_plist} #{plugin_uuids_key}`
latest_xcode_uuid = `defaults read /Applications/Xcode.app/Contents/Info #{xcode_uuid_key}`.gsub! "\n", ''
# If the value is already there, skip and optionally notify
if plugin_uuids.include? latest_xcode_uuid
uptodate_plugins += 1
puts "#{green}#{plugin} is already up to date." if DISPLAY_ALREADY_UPDATED
next
end
puts "#{yellow}Updating #{plugin}..."
system "defaults write #{plugin_plist} #{plugin_uuids_key} -array-add #{latest_xcode_uuid}"
updated_plugins += 1
end
if updated_plugins == 0
if uptodate_plugins == 1
puts "\n#{green}You have only one pluging, and it was already up to date.#{white}"
else
puts "\n#{green}All #{uptodate_plugins} plugins were already up to date.#{white}"
end
elsif uptodate_plugins == 0
if updated_plugins == 1
puts "\n#{green}You have only one plugin, and it has been updated."
else
puts "\n#{green}All #{updated_plugins} plugins have been updated."
end
elsif updated_plugins == 1 && uptodate_plugins == 1
puts "\n#{green}#{updated_plugins} plugin has been updated, #{uptodate_plugins} plugin was already up to date.#{white}"
elsif updated_plugins == 1
puts "\n#{green}#{updated_plugins} plugin has been updated, #{uptodate_plugins} plugins were already up to date.#{white}"
elsif uptodate_plugins == 1
puts "\n#{green}#{updated_plugins} plugins have been updated, #{uptodate_plugins} plugin was already up to date.#{white}"
else
puts "\n#{green}#{updated_plugins} plugins have been updated, #{uptodate_plugins} plugins were already up to date.#{white}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.