Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Reset all iOS simulators with this one weird trick
osascript -e 'tell application "iOS Simulator" to quit'
osascript -e 'tell application "Simulator" to quit'
xcrun simctl erase all

pretty good, but what about this one liner without the variable: xcrun simctl list devices | grep -v '^[-=]' | cut -d "(" -f2 | cut -d ")" -f1 | xargs -I {} xcrun simctl erase "{}"?


ZevEisenberg commented Sep 27, 2014

Nice. I couldn’t figure out how to do it because I have not the shell fu.

Man, I just spent an hour or two putting something like this together. This is so much simpler.

sixstringtheory I'd like to quote this in my book; may I?

This is awesome - thanks, @ZevEisenberg and @sixstringtheory

I think it would be even better to pipe another grep like grep -v 'unavailable' after the first one. Otherwise the output will contain also unavailable devices that doesn't make sense to reset

That's so f'ing handy.

About the only way I can think of improving this is to make a wrapper simctl that normally calls the real …/…/simctl, but when given simctl erase --all calls your code instead. ;-)

So… much cheers.

Since Xcode 7 it is possible to do xcrun simctl erase all and combined with your osascript -e 'tell application "iOS Simulator" to quit' this is perfect for putting it inside the before integration trigger of a Xcode bot


ZevEisenberg commented Dec 16, 2015

Thanks, @Blackjacx! Updated with the new first-party method of doing this.

Very useful, thanks!

jeanmw commented May 16, 2017

Yay, thanks so much this is super useful/convenient for testing!

neilt commented Sep 25, 2017

In Xcode 9, you can use xcrun simctl shutdown all to shutdown the simulators.

Thank you so much
it worked

the amount of disk this freed up is astounding, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment