Skip to content

Instantly share code, notes, and snippets.

@cmittendorf
Last active August 29, 2015 14:24
Show Gist options
  • Save cmittendorf/63f5e5e87d1379627e60 to your computer and use it in GitHub Desktop.
Save cmittendorf/63f5e5e87d1379627e60 to your computer and use it in GitHub Desktop.
From time to time, i.e. after installing Xcode beta versions, your devices menu is messed up and will show only a long list of identifiers and duplicates. This script will rebuild the iOS simulators menu by creating all possible combinations of devices and system versions.
#!/usr/bin/env ruby
device_types = []
runtimes = []
`xcrun simctl list`.each_line do |line|
device_type_id = /\((com\.apple\.CoreSimulator\.SimDeviceType\..*?)\)/.match(line)
if device_type_id then
device_types << device_type_id[1]
end
runtime_id = /\((com\.apple\.CoreSimulator\.SimRuntime\..*?)\)/.match(line)
if runtime_id then
runtimes << runtime_id[1]
end
identifier = /\(([A-Z0-9-]+)\)/.match(line)
if identifier then
`xcrun simctl delete #{identifier[1]}`
end
end
device_types.each do |device_type_id|
device_name = /SimDeviceType\.(.*?)$/.match(device_type_id)[1].gsub("-", " ")
runtimes.each do |runtime_id|
runtime_name = /(\d\-\d)$/.match(runtime_id)[1].gsub("-", ".")
command = "xcrun simctl create '#{device_name} (#{runtime_name})' '#{device_type_id}' '#{runtime_id}'"
system(command)
if $?.exitstatus != 0 then
puts "Cannot create '#{device_name} (#{runtime_name})'"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment