Skip to content

Instantly share code, notes, and snippets.

@ZevEisenberg
Last active November 30, 2022 09:27
Show Gist options
  • Save ZevEisenberg/5a172662cb576872d1ab to your computer and use it in GitHub Desktop.
Save ZevEisenberg/5a172662cb576872d1ab to your computer and use it in GitHub Desktop.
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
@lajosdeme
Copy link

This is amazing! Thanks a lot!

@ashermes
Copy link

ashermes commented Apr 1, 2019

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.

@MemoryReload
Copy link

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

@MemoryReload
Copy link

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 "{}"

@soffes
Copy link

soffes commented Nov 12, 2019

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.

@zfogg
Copy link

zfogg commented Oct 19, 2020

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

🥳

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