Quick Wipe of iOS Simulator Using Alfred
When I am rapidly prototyping new features, I frequently need to blow out the entire app structure from the simulator and start fresh.
To do this manually, I would follow the following steps.
From Simulator (when simulator is open)*: 1. Go to Menu Bar 2. Click iOS Simulator 3. Click Reset Content and Settings
Benefits of this approach:
- Easy to do/remember
- Blows out all settings and apps
Drawbacks to this approach
- Destroys ALL content, including any general settings
- I frequently need to test something more complex, like uploading images. I will save images to the simulator by going to Safari on the simulator and saving images form the web for use in the simulator’s photo library. Using the Reset Content option destroys all of this data and it has to be recreated.
- Simulator must already be running to reset settings
- Go to path:
~/[user]/Library/Application\ Support/iPhone\ Simulator/[SDK Version]/Applications
- Delete all folders in the Applications folder
Benefits of this approach
- Deletes apps from simulator without wiping settings
Drawbacks to this approach
- Very manual, even when you have a sidebar shortcut set up in the Finder
My solution: Alfred Simulator Wipe
I love the application Alfred. Alfred is an extremely useful app that started its life as an application launcher, and has evolved into a swiss army knife that is ultimately customizable and expandable. When I get on any Mac and hit
⌘ + space and see Spotlight instead of Alfred, I know my productivity will be less than normal. One of the best features of Alfred is the ability to create custom shell/Applescript extensions and run them from the app with a keyword (The devs just added the ability to pipe input into these scripts with v1.2, but I haven’t had a chance to play with it yet). This is the technique I used to automate the majority of this simulator wipe process (You have to have purchased the PowerPack to take advantage of extensions). Here is how to create an Alfred extension to wipe your Simulator applications:
- Download Alfred
- Open Alfred Preferences (with Alfred open, hit
⌘ + ,)
- Click the ‘+’ button at the bottom left of the window:
- Select AppleScript
- Enter an Extension Name. Other details are optional.
- To make it look nice in Alfred, you can drag in an icon that will be displayed in the app when the keyword is invoked
- Enter a title and description
- Pick a keyword that Alfred will use to launch the script
- Check the Background box (This allows the script to run and not block Alfred until it completes)
- Use the following code in the AppleScript field:
tell application “Finder” delete (every item of folder “[Drive]:Users:[user]:Library:Application Support:iPhone Simulator:5.1:Applications”) end tell
- The iOS simulator uses a separate directory for each installed SDK. For each iOS SDK on your system (I have 3), add a new line to delete that Simulator’s installed apps. You would simply copy the delete line above and change [5.1] to a different folder name.
- Click the Save button when you’re done
- Invoke Alfred, then type in the keyword you set up to run the extension
- You should wind up with something like you see below
This will easily wipe out your simulator apps without destroying any data in the simulator itself. It’s also a lot easier than going through the Finder every time. I’m linking to an export of the extension below. Please let me know in the comments if you are doing anything similar or you can think of any improvements!