Created
September 23, 2014 21:30
-
-
Save cabeca/cbaacbeb6a1cc4683aa5 to your computer and use it in GitHub Desktop.
This script removes and recreates all simulators in Xcode 6.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This worked brilliantly!
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.
Thank you guys! both solutions work great!
I can confirm the solution by @tinyfrog works. Thanks!
still good. thanks
You should use the --json
parameter to get machine processable output.
xcrun simctl list devices --json
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.+)$/
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
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
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