Last active
April 16, 2020 09:18
-
-
Save cabeca/3ff77007204e5479f7af to your computer and use it in GitHub Desktop.
This script removes and recreates all simulators in Xcode 7.
This file contains hidden or 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 | |
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']}` | |
end | |
end | |
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 | |
end | |
end |
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']}"
to
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
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.