Instantly share code, notes, and snippets.

Embed
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

This comment has been minimized.

armcknight commented Sep 27, 2014

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

This comment has been minimized.

Owner

ZevEisenberg commented Sep 27, 2014

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

@Sarkazein

This comment has been minimized.

Sarkazein commented Oct 7, 2014

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

@mattneub

This comment has been minimized.

mattneub commented Jan 28, 2015

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

@ArtSabintsev

This comment has been minimized.

ArtSabintsev commented Jan 29, 2015

This is awesome - thanks, @ZevEisenberg and @sixstringtheory

@vittoriom

This comment has been minimized.

vittoriom commented Aug 20, 2015

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

This comment has been minimized.

capnslipp commented Oct 21, 2015

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

This comment has been minimized.

Blackjacx commented Nov 10, 2015

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

This comment has been minimized.

Owner

ZevEisenberg commented Dec 16, 2015

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

@stanislaw

This comment has been minimized.

stanislaw commented Aug 26, 2016

Very useful, thanks!

@jeanmw

This comment has been minimized.

jeanmw commented May 16, 2017

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

@neilt

This comment has been minimized.

neilt commented Sep 25, 2017

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

@SupriyaKalghatgi

This comment has been minimized.

SupriyaKalghatgi commented Nov 13, 2017

Thank you so much
it worked

@sampurcell93

This comment has been minimized.

sampurcell93 commented Dec 20, 2017

the amount of disk this freed up is astounding, thanks

@armcknight

This comment has been minimized.

armcknight commented May 15, 2018

hah, just found this again! like the updated version, so much cleaner!

@consbulaquena

This comment has been minimized.

consbulaquena commented Jul 25, 2018

I thought there was a problem with the database, turns out the simulator only needs resetting!

xcrun simctl erase all

@CyberToro

This comment has been minimized.

CyberToro commented Nov 30, 2018

This is amazing! Thanks a lot!

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