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
@armcknight

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
Owner

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

@Sarkazein

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

@mattneub

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

@ArtSabintsev

This is awesome - thanks, @zeveisenberg and @sixstringtheory

@vittoriom

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

@capnslipp

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 …/Xcode.app/…/simctl, but when given simctl erase --all calls your code instead. ;-)

So… much cheers.

@Blackjacx

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
Owner

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

@stanislaw

Very useful, thanks!

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