---
title: "Updating Xcode plug-ins"
slug: updating-xcode-plug-ins
section: tech
date: 2015-11-25T18:19:00.000Z
canonical: https://roland.leth.ro/blog/tech/updating-xcode-plug-ins
---

I recently saw Joe's [post](http://www.mokacoding.com/blog/xcode-plugins-update/) about updating Xcode plug-ins, but since I'm really lazy, updating them one by one didn't suffice, so here's my take on it. In case you want to skip straight to the desert, [here](https://gist.github.com/rolandleth/d62345281678e7a27a26)'s the gist.

First, we change our script's directory:

```ruby
# You might need these.
# require 'pathname'
# require 'fileutils'

# In case we want to also print the already updated plug-ins
DISPLAY_ALREADY_UPDATED = false

plugin_path = File.expand_path('~/Library/Application Support/Developer/Shared/Xcode/Plug-ins')

Dir.chdir(plugin_path)
files =  Dir['*.xcplugin']
```

Then we iterate through the files:

```ruby
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
```

Then, at the end, the finishing touches:

```ruby
# For a bit of flavor
red    = "\e[31m"
green  = "\e[32m"
yellow = "\e[33m"
white  = "\e[0m"

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
```

*Thanks for the inspiration, Joe!*