Skip to content

Instantly share code, notes, and snippets.

@p4checo
Created July 25, 2019 11:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save p4checo/cc19acdc4e919555f72746a4d674f98e to your computer and use it in GitHub Desktop.
Save p4checo/cc19acdc4e919555f72746a4d674f98e to your computer and use it in GitHub Desktop.
Ruby script to list and selectively delete iOS simulators based on runtime
#!/usr/bin/env ruby
require 'JSON'
require 'optparse'
options = {}
OptionParser.new do |parser|
parser.banner = "Usage: simulator_cleaner.rb [options]"
parser.on("-h", "--help", "Show this help message") do ||
puts parser
exit
end
parser.on("-l", "--list-runtimes", "List the installed simulator runtimes") do |v|
options[:list] = true
end
parser.on("-d", "--delete-runtime RUNTIME", "Delete the installed simulator devices matching the provided runtime") do |v|
options[:delete] = true
options[:runtime] = v
end
end.parse!
if options[:list]
runtimes = JSON.parse `xcrun simctl list -j runtimes`
puts "Available runtimes:"
runtimes['runtimes'].each do |runtime|
puts "#{runtime['name']}"
end
exit
end
if options[:delete]
devices = JSON.parse `xcrun simctl list -j devices`
puts "Deleting simulators with runtime #{options[:runtime]}:"
devices['devices'].each do |runtime, runtime_devices|
if runtime == options[:runtime] then
runtime_devices.each do |device|
puts "Deleting simulator #{device['name']} (#{device['udid']})"
`xcrun simctl delete #{device['udid']}`
end
end
end
exit
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment