-
Star
(139)
You must be signed in to star a gist -
Fork
(17)
You must be signed in to fork a gist
-
-
Save ZevEisenberg/5a172662cb576872d1ab to your computer and use it in GitHub Desktop.
osascript -e 'tell application "iOS Simulator" to quit' | |
osascript -e 'tell application "Simulator" to quit' | |
xcrun simctl erase all |
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 …/Xcode.app/…/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
Thanks, @Blackjacx! Updated with the new first-party method of doing this.
Very useful, thanks!
Yay, thanks so much this is super useful/convenient for testing!
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
hah, just found this again! like the updated version, so much cleaner!
I thought there was a problem with the database, turns out the simulator only needs resetting!
xcrun simctl erase all
This is amazing! Thanks a lot!
Based on the answer above, I improved the command:
sudo killall -9 com.apple.CoreSimulator.CoreSimulatorService; xcrun simctl list devices | grep "iPhone\|iPad" | awk '{print $(NF -1)}' | cut -d "(" -f2 | cut -d ")" -f1 | xargs -I {} xcrun simctl erase "{}"
The first part (sudo killall) will make sure that the simulator is closed, so there won't be any simulator in Booted or Creating state (which will throw an error on delete).
I changed the UDID retrieval, as for devices like "iPad (5th generation) (D88F16C6-AEF4-40BF-A8A5-0CA2FB548A9D) (Shutdown)" it would pick up the incorrect text. In my version, it will always pick up the second to last word, instead of the 3rd word.
Also, when I get devices, I filter only iPhone and iPad simulators. This gives a bit of flexibility.
I use this combination as a hard reset for all my simulators.
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 "{}"
?
this grep-cut trick does not work fun now. :Q
Based on the answer above, I improved the command:
sudo killall -9 com.apple.CoreSimulator.CoreSimulatorService; xcrun simctl list devices | grep "iPhone\|iPad" | awk '{print $(NF -1)}' | cut -d "(" -f2 | cut -d ")" -f1 | xargs -I {} xcrun simctl erase "{}"
The first part (sudo killall) will make sure that the simulator is closed, so there won't be any simulator in Booted or Creating state (which will throw an error on delete).
I changed the UDID retrieval, as for devices like "iPad (5th generation) (D88F16C6-AEF4-40BF-A8A5-0CA2FB548A9D) (Shutdown)" it would pick up the incorrect text. In my version, it will always pick up the second to last word, instead of the 3rd word.Also, when I get devices, I filter only iPhone and iPad simulators. This gives a bit of flexibility.
I use this combination as a hard reset for all my simulators.
This also does not work fun, so I make a fix. : )
sudo killall -9 com.apple.CoreSimulator.CoreSimulatorService; xcrun simctl list devices | grep "iPhone\|iPad" | awk '{print $(NF -1)}' | cut -d "(" -f2 | cut -d ")" -f1 | grep -E "^[0-9A-F]{8}-([0-9A-F]{4}-){3}[0-9A-F]{12}$" | xargs -I {} xcrun simctl erase "{}"
I found this while looking to delete all simulators (instead of erase). If you want to do that, you can delete them all with xcrun simctl delete all
.
none of this stuff worked for me
# run this multiple times
pkill -flai xcode
# if any $process_id refuses to die and keeps printing out when doing the previous command, run this
kill -9 $process_id
🥳
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 "{}"
?