Skip to content

Instantly share code, notes, and snippets.

Last active April 16, 2020 09:18
  • Star 48 You must be signed in to star a gist
  • Fork 11 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
This script removes and recreates all simulators in Xcode 7.
#!/usr/bin/env ruby
require 'JSON'
device_types = JSON.parse `xcrun simctl list -j devicetypes`
runtimes = JSON.parse `xcrun simctl list -j runtimes`
devices = JSON.parse `xcrun simctl list -j devices`
devices['devices'].each do |runtime, runtime_devices|
runtime_devices.each do |device|
puts "Removing device #{device['name']} (#{device['udid']})"
`xcrun simctl delete #{device['udid']}`
device_types['devicetypes'].each do |device_type|
runtimes['runtimes'].select{|runtime| runtime['availability'] == '(available)'}.each do |runtime|
puts "Creating #{device_type['name']} with #{runtime['name']}"
command = "xcrun simctl create '#{device_type['name']} #{runtime['name']}' #{device_type['identifier']} #{runtime['identifier']}"
command_output = `#{command}`
sleep 0.5
Copy link

cabeca commented Oct 1, 2015

Warning: This is completely untested. It will REMOVE all your simulators along with all settings and installed Apps. It worked for me to create the initial set of simulators.

Copy link

Follow these guidelines to use this script :

Copy link

If you're using a more recent version of Ruby, you may need to change require 'JSON' to require 'json'

Copy link

v01pe commented Mar 23, 2016

Great, looks good! Just one strange thing - I get these errors:

Creating iPad Air 2 with iOS 9.2
Creating iPad Air 2 with tvOS 9.1
An error was encountered processing the command (, code=157):
Incompatible device
Creating iPad Air 2 with watchOS 2.1
An error was encountered processing the command (, code=157):
Incompatible device

for almost every device… I mean it doesn't seem to make sense to e.g. create "iPad Air 2 with tvOS 9.1", so I guess this is OK?
Maybe you can do some check in the inner loop when creating, to prevent these errors.

Copy link

Thanks for the script, it helps a lot. But it seems that it creates all simulators for every version and device in xcode, even they are not downloaded yet.

Copy link

ishaq commented May 30, 2016

If you are a CocoaPod writer, You might want to change line 19 from

command = "xcrun simctl create '#{device_type['name']} #{runtime['name']}' #{device_type['identifier']} #{runtime['identifier']}"


command = "xcrun simctl create '#{device_type['name']}' #{device_type['identifier']} #{runtime['identifier']}"

to omit generating simulator names like iPhone 4s iOS 9.3 and generate iPhone 4s instead, otherwise it causes: CocoaPods/CocoaPods#5320 (comment)

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