Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
This script removes and recreates all simulators in Xcode 6.
#!/usr/bin/env ruby
device_types_output = `xcrun simctl list devicetypes`
device_types = device_types_output.scan /(.*) \((.*)\)/
runtimes_output = `xcrun simctl list runtimes`
runtimes = runtimes_output.scan /(.*) \(.*\) \((com.apple[^)]+)\)$/
devices_output = `xcrun simctl list devices`
devices = devices_output.scan /\s\s\s\s(.*) \(([^)]+)\) (.*)/
devices.each do |device|
puts "Removing device #{device[0]} (#{device[1]})"
`xcrun simctl delete #{device[1]}`
end
device_types.each do |device_type|
runtimes.each do |runtime|
puts "Creating #{device_type} with #{runtime}"
command = "xcrun simctl create '#{device_type[0]} #{runtime[0]}' #{device_type[1]} #{runtime[1]}"
command_output = `#{command}`
sleep 0.5
end
end
@cabeca

This comment has been minimized.

Copy link
Owner Author

commented Sep 23, 2014

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.

Updated version for Xcode 7 here: https://gist.github.com/cabeca/3ff77007204e5479f7af

@bsneed

This comment has been minimized.

Copy link

commented Apr 4, 2015

This fixes the duplicate Simulators problem as well. Thanks so much!

@oscahie

This comment has been minimized.

Copy link

commented May 13, 2015

I was about to create exactly THIS, so thank you! It worked beautifully 😄 👍

@scaba

This comment has been minimized.

Copy link

commented May 28, 2015

This is great. Is there any way to make Xcode group the sims by iOS version? That would make it perfect.

@SpacyRicochet

This comment has been minimized.

Copy link

commented Jul 29, 2015

Much ❤️!

@vicwomg

This comment has been minimized.

Copy link

commented Jul 31, 2015

I really needed this, thanks! One potential issue is that it doesn't name the emulators exactly as the original Xcode does, so scripts depending on them to be named a certain way might not work (saw this when using Appium). Removing " #{runtime[0]}" from line 20 does the trick.

@shaobos

This comment has been minimized.

Copy link

commented Aug 1, 2015

Thanks for this great script. It helped me bring up several bad machines and saved a lot of time for my company. today i just found another way to get a clean slate for all simulators. No code is required:

  1. delete this entire directory ~/Library/Developer/CoreSimulator/Devices
  2. run launchctl list | grep CoreSimulator and then remove any processes from the output. For example: launchctl remove com.apple.CoreSimulator.CoreSimulatorService.117.15.1.dltcnwGXJZL4
  3. run xcrun simctl list. Setting DEVELOPER_DIR might be needed

I don't fully understand the rationale behind this but this seems to work fine for me.

@stevemoser

This comment has been minimized.

Copy link

commented Aug 4, 2015

The bash commands are probably simpler but you can try this for a easier yet more complex solution:
Per @saniul
gem install snapshot; snapshot reset_simulators

https://github.com/KrauseFx/snapshot

Per SO:
killall Xcode

sudo killall -9 com.apple.CoreSimulator.CoreSimulatorService

rm -rf ~/Library/Developer/CoreSimulator/Devices

open /Applications/Xcode.app

http://stackoverflow.com/a/31421158/142358

@AlexChesters

This comment has been minimized.

Copy link

commented Aug 7, 2015

This worked brilliantly!

@kk-achu

This comment has been minimized.

Copy link

commented Aug 25, 2015

Awesome...it works great...thank you so much..... before I tried deleting old Xcode and install new Xcode..thinking some thing wrong with Xcode...that didn't solve the problem..but this script did.

@fabiojgrocha

This comment has been minimized.

Copy link

commented Oct 1, 2015

Thank you guys! both solutions work great!

@werm098

This comment has been minimized.

Copy link

commented Jan 5, 2016

I can confirm the solution by @tinyfrog works. Thanks!

@johndpope-karhoo

This comment has been minimized.

Copy link

commented Sep 12, 2016

still good. thanks

@ollieatkinson

This comment has been minimized.

Copy link

commented Dec 16, 2016

You should use the --json parameter to get machine processable output.

xcrun simctl list devices --json
@oscahie

This comment has been minimized.

Copy link

commented Feb 16, 2018

In Xcode 9 Apple has changed the format of the output of xcrun simctl list runtimes, so to get it working again you'd need to update the regexp in line 7 to:
runtimes = runtimes_output.scan /(.*) \(.*\) - (com.apple.+)$/

@strobox

This comment has been minimized.

Copy link

commented Jan 7, 2019

In 2019 (and maybe >2019) do:

device_types_output = `xcrun simctl list devicetypes`
device_types = device_types_output.scan /(.*) \((.*)\)/


runtimes_output = `xcrun simctl list runtimes`
runtimes = runtimes_output.scan /(.*) \(.*\) - (com.apple[^)]+)$/

runtimes.each do |runtime|
  puts " #{runtime}"
end

devices_output = `xcrun simctl list devices`
devices = devices_output.scan /[A-Z0-9-]{36}/

devices.each do |device|
  puts "Removing device #{device}"
  `xcrun simctl delete #{device}`
end

device_types.each do |device_type|
  runtimes.each do |runtime|
    puts "Creating #{device_type} with #{runtime}"
    command = "xcrun simctl create '#{device_type[0]} #{runtime[0]}' #{device_type[1]} #{runtime[1]}"
    puts command
    command_output = `#{command}`
    sleep 0.5
  end
end
@strobox

This comment has been minimized.

Copy link

commented Jan 7, 2019

Or just for erase data:

#!/usr/bin/env ruby

devices_output = `xcrun simctl list devices`
devices = devices_output.scan /[A-Z0-9-]{36}/

devices.each do |device|
  puts "Erase device #{device} data"
  `xcrun simctl erase #{device}`
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.