Skip to content

Instantly share code, notes, and snippets.

@jfro
Created March 9, 2015 20:47
Show Gist options
  • Save jfro/cf788d0ac1cc61d4a378 to your computer and use it in GitHub Desktop.
Save jfro/cf788d0ac1cc61d4a378 to your computer and use it in GitHub Desktop.
re-creates simulators stuck in "Creating" state from Xcode 6.2 update
#!/bin/env ruby
deviceTypes = {
"iPhone 4s" => "com.apple.CoreSimulator.SimDeviceType.iPhone-4s",
"iPhone 5" => "com.apple.CoreSimulator.SimDeviceType.iPhone-5",
"iPhone 5s" => "com.apple.CoreSimulator.SimDeviceType.iPhone-5s",
"iPhone 6 Plus" => "com.apple.CoreSimulator.SimDeviceType.iPhone-6-Plus",
"iPhone 6" => "com.apple.CoreSimulator.SimDeviceType.iPhone-6",
"iPad 2" => "com.apple.CoreSimulator.SimDeviceType.iPad-2",
"iPad Retina" => "com.apple.CoreSimulator.SimDeviceType.iPad-Retina",
"iPad Air" => "com.apple.CoreSimulator.SimDeviceType.iPad-Air",
"Resizable iPhone" => "com.apple.CoreSimulator.SimDeviceType.Resizable-iPhone",
"Resizable iPad" => "com.apple.CoreSimulator.SimDeviceType.Resizable-iPad"}
simctl = "xcrun simctl"
puts "#{simctl} list"
out = %x{#{simctl} list}
out.lines.each do |line|
match = /(\s+)(.*)\s\(([\d\w]{8}-[\w\d]{4}-[\w\d]{4}-[\w\d]{4}-[\w\d]{12})\)\s\(Creating\)/.match(line)
if match
line = match[0]
id = match[3]
name = match[2]
if deviceTypes[name]
puts "Re-creating '#{name}' - #{deviceTypes[name]}"
result = system("#{simctl} delete #{id}")
if result
createResult = system("#{simctl} create '#{name}' #{deviceTypes[name]} com.apple.CoreSimulator.SimRuntime.iOS-8-2")
if not createResult
puts "Failed to re-create #{name}"
end
else
puts "Failed to Delete #{name} - #{id}"
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment