Created
July 25, 2019 11:20
-
-
Save p4checo/cc19acdc4e919555f72746a4d674f98e to your computer and use it in GitHub Desktop.
Ruby script to list and selectively delete iOS simulators based on runtime
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' | |
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