How can I reset the iOS Simulator from the command line?

I need to reset the iPhone Simulator a lot, and haven't found a way to do it without using the mouse. It's a small thing, but I'm really sick of doing it and would love to have a way to do this using a keyboard shortcut.

Even better would be a way to reset it from the command line, so I could build a reset into a deploy script.

I am not very familiar with iOS or MacOS.


Just run this in the terminal:

xcrun simctl shutdown all && xcrun simctl erase all

Another approach suggested by @txulu, before erasing the simulator kill the process:

killall "Simulator" 2> /dev/null; xcrun simctl erase all

In Xcode 6, DO NOT JUST DELETE THE FOLDER FOR THE SIMULATOR! It WILL screw things up, and it WILL cause you a headache.

In Xcode 6, there's actually a tool to control the simulator from the command line.

Make sure your command line settings are set to Xcode 6

xcrun simctl

In Xcode 6, each device has a GUID/UUID associated to it, to reset a specific device, you need the GUID for it.

The command

xcrun simctl list

will show you all of the devices you have set up. The output will look like this:

== Devices ==
-- iOS 7.0 --
iPhone 4s (F77DC0AE-6A6D-4D99-9936-F9DB07BBAA82) (Shutdown)
iPhone 5 (5B78FC0D-0034-4134-8B1F-19FD0EC9D581) (Shutdown)
iPhone 5s (569E5910-E32D-40E2-811F-D2E8F04EA4EF) (Shutdown)
iPad 2 (451DBBD8-A387-4E77-89BF-2B3CD45B4772) (Shutdown)
iPad Retina (2C58366B-5B60-4687-8031-6C67383D793F) (Shutdown)
iPad Air (50E03D3B-3456-4C49-85AD-60B3AFE4918B) (Shutdown)
-- iOS 7.1 --
-- iOS 8.0 --
iPhone 4s (27818821-A0BB-496E-A956-EF876FB514C2) (Shutdown)
iPhone 5 (6FBAA7E2-857C-432A-BD03-980D762DA9D2) (Shutdown)
iPhone 5s (7675C82B-DE49-45EB-A28D-1175376AEEE9) (Shutdown)
iPad 2 (836E7C89-B9D6-4CC5-86DE-B18BA8600E7B) (Shutdown)
iPad Retina (EFDD043D-2725-47DC-A3FF-C984F839A631) (Shutdown)
iPad Air (9079AD6C-E74D-4D5F-9A0F-4933498B852E) (Shutdown)
Resizable iPhone (943CFEDE-A03C-4298-93E3-40D0713652CB) (Shutdown)
Resizable iPad (DBA71CA5-6426-484B-8E9B-13FCB3B27DEB) (Shutdown)

Just copy the GUID from inside the parentheses, and run xcrun simctl erase

for example,

xcrun simctl erase 5B78FC0D-0034-4134-8B1F-19FD0EC9D581

would erase the iOS 7.0, iPhone 5 device


Thought I'd post this for anyone who runs into the same need. Someone on reddit gave me this solution (which I tested and it works great). Note that this time you need an ellipsis after "Settings", not three periods (weird).

This is an AppleScript that can be invoked from the command line to reset the Simulator:

tell application "iPhone Simulator"
    activate
end tell

tell application "System Events"
    tell process "iPhone Simulator"
        tell menu bar 1
            tell menu bar item "iOs Simulator"
                tell menu "iOs Simulator"
                    click menu item "Reset Content and Settings…"
                end tell
            end tell
        end tell
        tell window 1
            click button "Reset"
        end tell
    end tell
end tell

Save as /path/to/script and invoke with:

osascript /path/to/script

COPY-PASTE ANSWER - note: will reset the contents and settings of all available simulators.

Thanks @Alpine for the inspiration and knowledge. If you run this in your command line you should be able to reset all the available sims. This works with Xcode 6.

# Get the sim list with the UUIDs
OUTPUT="$(xcrun simctl list)"
# Parse out the UUIDs and saves them to file
echo $OUTPUT | awk -F "[()]" '{ for (i=2; i<NF; i+=2) print $i }' | grep '^[-A-Z0-9]*$' > output.txt
# Iterate through file and reset sim
for UUID in `awk '{ print $1 }' output.txt`
do
xcrun simctl erase $UUID
done