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.
我需要重置iPhone模拟器很多,而且没有找到一种不用鼠标就能做到的方法。这是一件小事,但我真的很讨厌这样做,而且我很想用快捷键来做这件事。
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.
我不太熟悉iOS或MacOS。
17 个解决方案
#1
54
In Xcode 6, DO NOT JUST DELETE THE FOLDER FOR THE SIMULATOR! It WILL screw things up, and it WILL cause you a headache.
在Xcode 6中,不要只删除模拟器的文件夹!它会把事情搞砸,会让你头疼。
In Xcode 6, there's actually a tool to control the simulator from the command line.
在Xcode 6中,实际上有一个工具可以从命令行控制模拟器。
Make sure your command line settings are set to Xcode 6
确保您的命令行设置设置为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.
在Xcode 6中,每个设备都有一个与之相关的GUID/UUID,来重置一个特定的设备,您需要它的GUID。
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
只需从括号内复制GUID,并运行xcrun simctl删除。
for example,
例如,
xcrun simctl erase 5B78FC0D-0034-4134-8B1F-19FD0EC9D581
would erase the iOS 7.0, iPhone 5 device
会擦除ios7.0, iPhone 5设备吗?
#2
54
simple :
简单:
xcrun simctl erase all
improvement suggested by @txulu, just kill the simulator before execute the clean:
@txulu建议的改进,在执行clean之前先杀死模拟器:
killall "Simulator" 2> /dev/null; xcrun simctl erase all
#3
35
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).
我想我会把这篇文章寄给任何遇到同样需要的人。reddit上的某个人给了我这个解决方案(我测试过,效果很好)。请注意,这一次您需要在“设置”之后使用省略号,而不是3个周期(奇怪)。
This is an AppleScript that can be invoked from the command line to reset the Simulator:
这是一个AppleScript,可以从命令行调用来重置模拟器:
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:
保存为/path/to/脚本并调用:
osascript /path/to/script
#4
16
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.
感谢@Alpine提供的灵感和知识。如果您在命令行中运行此操作,您应该能够重置所有可用的sims。这与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
#5
11
Delete the contents of
删除的内容
~/Library/Application Support/iPhone Simulator/<sdk revision>
And you're good to go.
你很好。
#6
4
The keyboard short-cut solution is not relevant anymore and unfortunately @Cameron solution didn't work for me either (I tried to debug it with no luck)
键盘快捷键不再适用,不幸的是,@Cameron解决方案也对我不起作用(我试图调试它,但没有成功)
Here is what works for me:
下面是我的工作:
#!/bin/bash
# `menu_click`, by Jacob Rus, September 2006
#
# Accepts a list of form: `{"Finder", "View", "Arrange By", "Date"}`
# Execute the specified menu item. In this case, assuming the Finder
# is the active application, arranging the frontmost folder by date.
osascript <<SCRIPT
on menu_click(mList)
local appName, topMenu, r
-- Validate our input
if mList's length < 3 then error "Menu list is not long enough"
-- Set these variables for clarity and brevity later on
set {appName, topMenu} to (items 1 through 2 of mList)
set r to (items 3 through (mList's length) of mList)
-- This overly-long line calls the menu_recurse function with
-- two arguments: r, and a reference to the top-level menu
tell application "System Events" to my menu_click_recurse(r, ((process appName)'s ¬
(menu bar 1)'s (menu bar item topMenu)'s (menu topMenu)))
end menu_click
on menu_click_recurse(mList, parentObject)
local f, r
-- `f` = first item, `r` = rest of items
set f to item 1 of mList
if mList's length > 1 then set r to (items 2 through (mList's length) of mList)
-- either actually click the menu item, or recurse again
tell application "System Events"
if mList's length is 1 then
click parentObject's menu item f
else
my menu_click_recurse(r, (parentObject's (menu item f)'s (menu f)))
end if
end tell
end menu_click_recurse
application "iPhone Simulator" activate
menu_click({"iPhone Simulator", "iOS Simulator", "Reset Content and Settings…"})
tell application "System Events"
tell process "iPhone Simulator"
tell window 1
click button "Reset"
end tell
end tell
end tell
SCRIPT
#7
3
Upon installing Xcode I always create a keyboard shortcut for "Reset Content and Settings" in the simulator. An extremely useful time saver.
在安装Xcode时,我总是在模拟器中创建一个“重置内容和设置”的快捷键。非常有用的节省时间。
System Preferences > Keyboard > Shortcuts > App Shortcuts > "+"
系统偏好>键盘>快捷键>程序快捷键> "+"
In the Application picker, select "Other..." to open the app picker dialog.
在应用程序选择器中,选择“Other…”来打开app选择器对话框。
In this dialog you're unable to "Show Package Contents" to explore a .app, so you'll need to use Go to Folder
via Cmd-Shift-G. (First open the application drop down and select Other
)
在这个对话框中,您无法“显示包内容”来探索一个.app,因此您需要通过Cmd-Shift-G来使用到文件夹。(首先打开应用程序,然后选择其他)
In the current version of Xcode, go to the path:
在当前版本的Xcode中,选择路径:
/Applications/Xcode/Contents/Developer/Applications
/应用程序/ Xcode /内容/开发/应用程序
Select Simulator.app
and press "Add"
选择模拟器。应用程序并按“添加”
For Menu Title
, enter Reset Content and Settings...
对于菜单标题,输入重置内容和设置…
For Keyboard Shortcut
, press CMD-Shift-R
对于键盘快捷键,按CMD-Shift-R。
#8
1
I wrote a script that will reset the contents & settings of all versions and devices for the iOS Simulator. It grabs the device names and version numbers from the menu, so it will include any new devices or iOS versions that Apple releases simulators for.
我编写了一个脚本,它将重置iOS模拟器的所有版本和设备的内容和设置。它从菜单中获取设备名称和版本号,因此它将包括苹果发布的任何新设备或iOS版本。
It's easy to run manually or use in a build-script. I would suggest adding it as a Pre-Action Run Script before the build.
很容易在构建脚本中手动运行或使用。我建议在构建之前将其添加为预操作运行脚本。
It's based heavily on Stian's script above, but doesn't become stale with new iOS versions, and eliminates the dialog box (better for automation build scripts and working from the command-line).
它主要基于Stian的脚本,但不会因为新的iOS版本而变得陈旧,并且消除了对话框(更好的是自动化构建脚本和从命令行工作)。
https://github.com/michaelpatzer/ResetAllSimulators
https://github.com/michaelpatzer/ResetAllSimulators
#9
1
I have found this very helpful tool called "SimulatorManager": http://tue-savvy.github.io It will reset all you simulators by means of a menu bar widget (not sure if that's what its called) but on top of that it will give you quick access to all your application data. I really can't live without it anymore. Spread the word!
我发现了这个非常有用的工具,叫做“SimulatorManager”:http://tue-savvy.github。io它会通过一个菜单栏小部件(不确定这是不是它的名字)来重置所有的模拟器,但是它会让你快速访问所有的应用程序数据。没有它我真的活不下去了。传播这个词!
#10
1
I checked it with XCode 9. To close all active simulators run:
我用XCode 9检查了一下。关闭所有主动模拟器运行:
xcrun simctl shutdown all
To reset all simulators run:
重置所有模拟器运行:
xcrun simctl erase all
You can filter what simulator to close/reset like this:
你可以像这样过滤模拟器的关闭/复位:
xcrun simctl shutdown F36B238F-3ED6-4E10-BB5A-0726151916FA
xcrun simctl erase F36B238F-3ED6-4E10-BB5A-0726151916FA
Find all accessible simulators (and their GUID) on your machine like this:
在你的机器上找到所有可访问的模拟器(和它们的GUID):
xcrun instruments -s
To run any simulator by GUID:
使用GUID运行任何模拟器:
xcrun instruments -w F36B238F-3ED6-4E10-BB5A-0726151916FA -t Blank
To install app to the booted simulator:
将app安装到引导模拟器:
xcrun simctl install booted /path/to/your.app
To remove app from the booted simulator:
从引导模拟器中删除应用程序:
xcrun simctl uninstall booted /path/to/your.app
To launch the app in the booted simulator:
在引导模拟器中启动应用程序:
xcrun simctl launch booted "com.app.bundleIdentifier"
"com.app.bundleIdentifier" is your CFBundleIdentifier in Info.plist
“com.app。“bundleIdentifier”是Info.plist中的CFBundleIdentifier。
#11
0
I want to add something to Cameron Brown's answer. To make sure the correct version is resetted (e.g, iPad, version 6.1), I start the iOS Simulator via ios-sim:
我想给卡梅伦·布朗的回答加点东西。要确保正确的版本被重新设置(e)。g, iPad, version 6.1),我通过iOS -sim启动iOS模拟器:
version=$(echo "$DESTINATION" | egrep -o "OS=[0-9.]{3}" | cut -d '=' -f 2)
simType=$(echo "$DESTINATION" | egrep -o "name=[a-zA-Z]*" | cut -d '=' -f 2 | tr "[A-Z]" "[a-z]")
IOS_SIM_BIN=$(which ios-sim)
if [ -z $IOS_SIM_BIN ]
then
echo "ios-sim not installed, please use 'sudo npm install ios-sim -g'"
fi
echo "Resetting Simulator \"$simType\", version \"$version\""
$IOS_SIM_BIN start --family $simType --sdk $version --timeout 1
osascript /path/to/reset_simulator.applescript
$DESTINATION
can be e.g "OS=7.0,name=iPad"
.
目的地美元可以e。g“OS = 7.0,name = iPad”。
For that to work correctly, I adapted the reset_simulator.applescript a bit and removed the activation part:
为了正确地工作,我调整了reset_simulator。applescript稍微删除了激活部分:
tell application "iPhone Simulator"
activate
end tell
#12
0
As an added bonus to using the xcrun commands you can launch a device after you listed with
作为使用xcrun命令的额外奖励,您可以在列出后启动一个设备。
xcrun simctl list
Once you have the list displayed run:
一旦你有了列表显示运行:
xcrun instruments -w "iPhone 5s (8.1 Simulator) [31E5EF01-084B-471B-8AC6-C1EA3167DA9E]"
#13
0
We use the following python script to reset the simulator on our build server.
我们使用下面的python脚本来重置构建服务器上的模拟器。
#!/usr/bin/env python
import subprocess
import re
import os
def uninstall_app():
print 'Running %s' % __file__
# Get (maybe read from argv) your bundle identifier e.g. com.mysite.app_name
try:
bundle_identifier = '$' + os.environ['BUNDLE_IDENTIFIER']
except KeyError, e:
print 'Environment variable %s not found. ' % e
print 'Environment: ', os.environ
exit(1)
print 'Uninstalling app with Bundle identifier: ', bundle_identifier
# We call xcrun, and strip the device GUIDs from the output
process = subprocess.Popen(['xcrun', 'simctl', 'list'], stdout=subprocess.PIPE)
# Read first line
line = process.stdout.readline()
while True:
# Assume first match inside parenthesis is what we want
m = re.search('\((.*?)\)', line)
if not (m is None):
# The regex found something,
# group(1) will throw away the surrounding parenthesis
device_GUID = m.group(1)
# Brutely call uninstall on all listed devices. We know some of these will fail and output an error, but, well..
subprocess.call(['xcrun', 'simctl', 'uninstall', device_GUID, bundle_identifier])
# Read next line
line = process.stdout.readline()
# Stop condition
if line == '':
break
if __name__ == '__main__':
uninstall_app()
It assumse your app's bundle identifier is set as an environment variable, e.g.
它假定您的应用程序的bundle标识符被设置为一个环境变量,例如。
export BUNDLE_IDENTIFIER=com.example.app_name
maybe you'd want to pass the bundle identifier in another way.
也许您希望以另一种方式传递bundle标识符。
#14
0
Building on most of the answers above, I am using Keyboard Maestro and made a little Macro to reset the currently running Simulator and restarting it. It turns the focus back to Xcode after resetting and restarting, so I can hit Command+R
again right away to re-run the app, which I find very convenient.
在上面大多数答案的基础上,我使用键盘大师,并做了一个小宏来重置当前运行的模拟器并重新启动它。在重新设置和重新启动之后,将焦点转回Xcode,这样我就可以再次点击Command+R来重新运行应用程序,我觉得这很方便。
The content of the ruby script is:
ruby脚本的内容是:
#!/usr/bin/env ruby
list = `xcrun simctl list`.split("\n")
list.each do |line|
if line =~ /\(Booted\)$/
device = line.match(/([^(]*)\s+\(([^)]*)\)\s+\(([^)]*)\).*/)[1]
uuid = line.match(/([^(]*)\s+\(([^)]*)\)\s+\(([^)]*)\).*/)[2]
status = line.match(/([^(]*)\s+\(([^)]*)\)\s+\(([^)]*)\).*/)[3]
puts uuid
break
end
end
#15
0
Here's a Rakefile task to reset a targeted simulator. This works with Xcode 7 since the Xcode 7 command line tools broke the xcrun simctl uninstall command. I have a little custom runC method since I like to see the actual terminal command as well as its output.
这里有一个Rakefile任务来重置目标模拟器。这与Xcode 7一起工作,因为Xcode 7命令行工具打破了xcrun simctl卸载命令。我有一个小的自定义runC方法,因为我喜欢看到实际的终端命令以及它的输出。
desc "Resets the iPhone Simulator state"
task :reset_simulator => [] do
deviceDestinationName = 'iPhone 6' #for efficiency since we only target one device for our unit tests
puts "...starting simulator reset"
runC('killall "iOS Simulator"')
runC('killall "Simulator"')
runC('xcrun simctl list > deviceList.txt')
lines = File.open('deviceList.txt').readlines
lines.each do |line|
lineStripped = line.strip
if (lineStripped=~/[a-zA-Z0-9]{8}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{12}/)
if (lineStripped !~ /unavailable/ && lineStripped.include?("#{deviceDestinationName} ("))
puts "Inspecting simulator: #{lineStripped} by making sure it is shut down, then erasing it."
needsShutdown = !lineStripped.include?('Shutdown')
aDeviceId = lineStripped[/[a-zA-Z0-9]{8}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{12}/]
if (needsShutdown)
runC("xcrun simctl shutdown #{aDeviceId}")
end
runC("xcrun simctl erase #{aDeviceId}")
#does not work to just uninstall the app with Xcode 7, do just rely on resetting the device above
#`xcrun simctl uninstall #{aDeviceId} com.animoto.AppServiceClientTester`
end
end
end
runC('rm deviceList.txt')
end
#Runs a command and prints out both the command that will be run and the results
def runC(command)
puts '$ ' + command
puts `#{command}`
end
#16
-1
target names and Simulator app name seem to have changed a bit to xCode6 / iOS8. Here is un updated version of Cameron Brown's osascript for xCode6 / iOS8:
目标名称和模拟器应用程序名称似乎已经改变了一点到xCode6 / iOS8。以下是卡梅伦·布朗关于xCode6 / iOS8的osascript的更新版本:
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
#17
-4
I present,
我现在,
The Definitive iOS Simulator Reset Script (link)
Based on Oded Regev's code (which was based on Jacob Rus's fine "menu_click" code)
基于Oded Regev的代码(基于Jacob Rus的fine“menu_click”代码)
#1
54
In Xcode 6, DO NOT JUST DELETE THE FOLDER FOR THE SIMULATOR! It WILL screw things up, and it WILL cause you a headache.
在Xcode 6中,不要只删除模拟器的文件夹!它会把事情搞砸,会让你头疼。
In Xcode 6, there's actually a tool to control the simulator from the command line.
在Xcode 6中,实际上有一个工具可以从命令行控制模拟器。
Make sure your command line settings are set to Xcode 6
确保您的命令行设置设置为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.
在Xcode 6中,每个设备都有一个与之相关的GUID/UUID,来重置一个特定的设备,您需要它的GUID。
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
只需从括号内复制GUID,并运行xcrun simctl删除。
for example,
例如,
xcrun simctl erase 5B78FC0D-0034-4134-8B1F-19FD0EC9D581
would erase the iOS 7.0, iPhone 5 device
会擦除ios7.0, iPhone 5设备吗?
#2
54
simple :
简单:
xcrun simctl erase all
improvement suggested by @txulu, just kill the simulator before execute the clean:
@txulu建议的改进,在执行clean之前先杀死模拟器:
killall "Simulator" 2> /dev/null; xcrun simctl erase all
#3
35
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).
我想我会把这篇文章寄给任何遇到同样需要的人。reddit上的某个人给了我这个解决方案(我测试过,效果很好)。请注意,这一次您需要在“设置”之后使用省略号,而不是3个周期(奇怪)。
This is an AppleScript that can be invoked from the command line to reset the Simulator:
这是一个AppleScript,可以从命令行调用来重置模拟器:
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:
保存为/path/to/脚本并调用:
osascript /path/to/script
#4
16
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.
感谢@Alpine提供的灵感和知识。如果您在命令行中运行此操作,您应该能够重置所有可用的sims。这与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
#5
11
Delete the contents of
删除的内容
~/Library/Application Support/iPhone Simulator/<sdk revision>
And you're good to go.
你很好。
#6
4
The keyboard short-cut solution is not relevant anymore and unfortunately @Cameron solution didn't work for me either (I tried to debug it with no luck)
键盘快捷键不再适用,不幸的是,@Cameron解决方案也对我不起作用(我试图调试它,但没有成功)
Here is what works for me:
下面是我的工作:
#!/bin/bash
# `menu_click`, by Jacob Rus, September 2006
#
# Accepts a list of form: `{"Finder", "View", "Arrange By", "Date"}`
# Execute the specified menu item. In this case, assuming the Finder
# is the active application, arranging the frontmost folder by date.
osascript <<SCRIPT
on menu_click(mList)
local appName, topMenu, r
-- Validate our input
if mList's length < 3 then error "Menu list is not long enough"
-- Set these variables for clarity and brevity later on
set {appName, topMenu} to (items 1 through 2 of mList)
set r to (items 3 through (mList's length) of mList)
-- This overly-long line calls the menu_recurse function with
-- two arguments: r, and a reference to the top-level menu
tell application "System Events" to my menu_click_recurse(r, ((process appName)'s ¬
(menu bar 1)'s (menu bar item topMenu)'s (menu topMenu)))
end menu_click
on menu_click_recurse(mList, parentObject)
local f, r
-- `f` = first item, `r` = rest of items
set f to item 1 of mList
if mList's length > 1 then set r to (items 2 through (mList's length) of mList)
-- either actually click the menu item, or recurse again
tell application "System Events"
if mList's length is 1 then
click parentObject's menu item f
else
my menu_click_recurse(r, (parentObject's (menu item f)'s (menu f)))
end if
end tell
end menu_click_recurse
application "iPhone Simulator" activate
menu_click({"iPhone Simulator", "iOS Simulator", "Reset Content and Settings…"})
tell application "System Events"
tell process "iPhone Simulator"
tell window 1
click button "Reset"
end tell
end tell
end tell
SCRIPT
#7
3
Upon installing Xcode I always create a keyboard shortcut for "Reset Content and Settings" in the simulator. An extremely useful time saver.
在安装Xcode时,我总是在模拟器中创建一个“重置内容和设置”的快捷键。非常有用的节省时间。
System Preferences > Keyboard > Shortcuts > App Shortcuts > "+"
系统偏好>键盘>快捷键>程序快捷键> "+"
In the Application picker, select "Other..." to open the app picker dialog.
在应用程序选择器中,选择“Other…”来打开app选择器对话框。
In this dialog you're unable to "Show Package Contents" to explore a .app, so you'll need to use Go to Folder
via Cmd-Shift-G. (First open the application drop down and select Other
)
在这个对话框中,您无法“显示包内容”来探索一个.app,因此您需要通过Cmd-Shift-G来使用到文件夹。(首先打开应用程序,然后选择其他)
In the current version of Xcode, go to the path:
在当前版本的Xcode中,选择路径:
/Applications/Xcode/Contents/Developer/Applications
/应用程序/ Xcode /内容/开发/应用程序
Select Simulator.app
and press "Add"
选择模拟器。应用程序并按“添加”
For Menu Title
, enter Reset Content and Settings...
对于菜单标题,输入重置内容和设置…
For Keyboard Shortcut
, press CMD-Shift-R
对于键盘快捷键,按CMD-Shift-R。
#8
1
I wrote a script that will reset the contents & settings of all versions and devices for the iOS Simulator. It grabs the device names and version numbers from the menu, so it will include any new devices or iOS versions that Apple releases simulators for.
我编写了一个脚本,它将重置iOS模拟器的所有版本和设备的内容和设置。它从菜单中获取设备名称和版本号,因此它将包括苹果发布的任何新设备或iOS版本。
It's easy to run manually or use in a build-script. I would suggest adding it as a Pre-Action Run Script before the build.
很容易在构建脚本中手动运行或使用。我建议在构建之前将其添加为预操作运行脚本。
It's based heavily on Stian's script above, but doesn't become stale with new iOS versions, and eliminates the dialog box (better for automation build scripts and working from the command-line).
它主要基于Stian的脚本,但不会因为新的iOS版本而变得陈旧,并且消除了对话框(更好的是自动化构建脚本和从命令行工作)。
https://github.com/michaelpatzer/ResetAllSimulators
https://github.com/michaelpatzer/ResetAllSimulators
#9
1
I have found this very helpful tool called "SimulatorManager": http://tue-savvy.github.io It will reset all you simulators by means of a menu bar widget (not sure if that's what its called) but on top of that it will give you quick access to all your application data. I really can't live without it anymore. Spread the word!
我发现了这个非常有用的工具,叫做“SimulatorManager”:http://tue-savvy.github。io它会通过一个菜单栏小部件(不确定这是不是它的名字)来重置所有的模拟器,但是它会让你快速访问所有的应用程序数据。没有它我真的活不下去了。传播这个词!
#10
1
I checked it with XCode 9. To close all active simulators run:
我用XCode 9检查了一下。关闭所有主动模拟器运行:
xcrun simctl shutdown all
To reset all simulators run:
重置所有模拟器运行:
xcrun simctl erase all
You can filter what simulator to close/reset like this:
你可以像这样过滤模拟器的关闭/复位:
xcrun simctl shutdown F36B238F-3ED6-4E10-BB5A-0726151916FA
xcrun simctl erase F36B238F-3ED6-4E10-BB5A-0726151916FA
Find all accessible simulators (and their GUID) on your machine like this:
在你的机器上找到所有可访问的模拟器(和它们的GUID):
xcrun instruments -s
To run any simulator by GUID:
使用GUID运行任何模拟器:
xcrun instruments -w F36B238F-3ED6-4E10-BB5A-0726151916FA -t Blank
To install app to the booted simulator:
将app安装到引导模拟器:
xcrun simctl install booted /path/to/your.app
To remove app from the booted simulator:
从引导模拟器中删除应用程序:
xcrun simctl uninstall booted /path/to/your.app
To launch the app in the booted simulator:
在引导模拟器中启动应用程序:
xcrun simctl launch booted "com.app.bundleIdentifier"
"com.app.bundleIdentifier" is your CFBundleIdentifier in Info.plist
“com.app。“bundleIdentifier”是Info.plist中的CFBundleIdentifier。
#11
0
I want to add something to Cameron Brown's answer. To make sure the correct version is resetted (e.g, iPad, version 6.1), I start the iOS Simulator via ios-sim:
我想给卡梅伦·布朗的回答加点东西。要确保正确的版本被重新设置(e)。g, iPad, version 6.1),我通过iOS -sim启动iOS模拟器:
version=$(echo "$DESTINATION" | egrep -o "OS=[0-9.]{3}" | cut -d '=' -f 2)
simType=$(echo "$DESTINATION" | egrep -o "name=[a-zA-Z]*" | cut -d '=' -f 2 | tr "[A-Z]" "[a-z]")
IOS_SIM_BIN=$(which ios-sim)
if [ -z $IOS_SIM_BIN ]
then
echo "ios-sim not installed, please use 'sudo npm install ios-sim -g'"
fi
echo "Resetting Simulator \"$simType\", version \"$version\""
$IOS_SIM_BIN start --family $simType --sdk $version --timeout 1
osascript /path/to/reset_simulator.applescript
$DESTINATION
can be e.g "OS=7.0,name=iPad"
.
目的地美元可以e。g“OS = 7.0,name = iPad”。
For that to work correctly, I adapted the reset_simulator.applescript a bit and removed the activation part:
为了正确地工作,我调整了reset_simulator。applescript稍微删除了激活部分:
tell application "iPhone Simulator"
activate
end tell
#12
0
As an added bonus to using the xcrun commands you can launch a device after you listed with
作为使用xcrun命令的额外奖励,您可以在列出后启动一个设备。
xcrun simctl list
Once you have the list displayed run:
一旦你有了列表显示运行:
xcrun instruments -w "iPhone 5s (8.1 Simulator) [31E5EF01-084B-471B-8AC6-C1EA3167DA9E]"
#13
0
We use the following python script to reset the simulator on our build server.
我们使用下面的python脚本来重置构建服务器上的模拟器。
#!/usr/bin/env python
import subprocess
import re
import os
def uninstall_app():
print 'Running %s' % __file__
# Get (maybe read from argv) your bundle identifier e.g. com.mysite.app_name
try:
bundle_identifier = '$' + os.environ['BUNDLE_IDENTIFIER']
except KeyError, e:
print 'Environment variable %s not found. ' % e
print 'Environment: ', os.environ
exit(1)
print 'Uninstalling app with Bundle identifier: ', bundle_identifier
# We call xcrun, and strip the device GUIDs from the output
process = subprocess.Popen(['xcrun', 'simctl', 'list'], stdout=subprocess.PIPE)
# Read first line
line = process.stdout.readline()
while True:
# Assume first match inside parenthesis is what we want
m = re.search('\((.*?)\)', line)
if not (m is None):
# The regex found something,
# group(1) will throw away the surrounding parenthesis
device_GUID = m.group(1)
# Brutely call uninstall on all listed devices. We know some of these will fail and output an error, but, well..
subprocess.call(['xcrun', 'simctl', 'uninstall', device_GUID, bundle_identifier])
# Read next line
line = process.stdout.readline()
# Stop condition
if line == '':
break
if __name__ == '__main__':
uninstall_app()
It assumse your app's bundle identifier is set as an environment variable, e.g.
它假定您的应用程序的bundle标识符被设置为一个环境变量,例如。
export BUNDLE_IDENTIFIER=com.example.app_name
maybe you'd want to pass the bundle identifier in another way.
也许您希望以另一种方式传递bundle标识符。
#14
0
Building on most of the answers above, I am using Keyboard Maestro and made a little Macro to reset the currently running Simulator and restarting it. It turns the focus back to Xcode after resetting and restarting, so I can hit Command+R
again right away to re-run the app, which I find very convenient.
在上面大多数答案的基础上,我使用键盘大师,并做了一个小宏来重置当前运行的模拟器并重新启动它。在重新设置和重新启动之后,将焦点转回Xcode,这样我就可以再次点击Command+R来重新运行应用程序,我觉得这很方便。
The content of the ruby script is:
ruby脚本的内容是:
#!/usr/bin/env ruby
list = `xcrun simctl list`.split("\n")
list.each do |line|
if line =~ /\(Booted\)$/
device = line.match(/([^(]*)\s+\(([^)]*)\)\s+\(([^)]*)\).*/)[1]
uuid = line.match(/([^(]*)\s+\(([^)]*)\)\s+\(([^)]*)\).*/)[2]
status = line.match(/([^(]*)\s+\(([^)]*)\)\s+\(([^)]*)\).*/)[3]
puts uuid
break
end
end
#15
0
Here's a Rakefile task to reset a targeted simulator. This works with Xcode 7 since the Xcode 7 command line tools broke the xcrun simctl uninstall command. I have a little custom runC method since I like to see the actual terminal command as well as its output.
这里有一个Rakefile任务来重置目标模拟器。这与Xcode 7一起工作,因为Xcode 7命令行工具打破了xcrun simctl卸载命令。我有一个小的自定义runC方法,因为我喜欢看到实际的终端命令以及它的输出。
desc "Resets the iPhone Simulator state"
task :reset_simulator => [] do
deviceDestinationName = 'iPhone 6' #for efficiency since we only target one device for our unit tests
puts "...starting simulator reset"
runC('killall "iOS Simulator"')
runC('killall "Simulator"')
runC('xcrun simctl list > deviceList.txt')
lines = File.open('deviceList.txt').readlines
lines.each do |line|
lineStripped = line.strip
if (lineStripped=~/[a-zA-Z0-9]{8}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{12}/)
if (lineStripped !~ /unavailable/ && lineStripped.include?("#{deviceDestinationName} ("))
puts "Inspecting simulator: #{lineStripped} by making sure it is shut down, then erasing it."
needsShutdown = !lineStripped.include?('Shutdown')
aDeviceId = lineStripped[/[a-zA-Z0-9]{8}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{12}/]
if (needsShutdown)
runC("xcrun simctl shutdown #{aDeviceId}")
end
runC("xcrun simctl erase #{aDeviceId}")
#does not work to just uninstall the app with Xcode 7, do just rely on resetting the device above
#`xcrun simctl uninstall #{aDeviceId} com.animoto.AppServiceClientTester`
end
end
end
runC('rm deviceList.txt')
end
#Runs a command and prints out both the command that will be run and the results
def runC(command)
puts '$ ' + command
puts `#{command}`
end
#16
-1
target names and Simulator app name seem to have changed a bit to xCode6 / iOS8. Here is un updated version of Cameron Brown's osascript for xCode6 / iOS8:
目标名称和模拟器应用程序名称似乎已经改变了一点到xCode6 / iOS8。以下是卡梅伦·布朗关于xCode6 / iOS8的osascript的更新版本:
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
#17
-4
I present,
我现在,
The Definitive iOS Simulator Reset Script (link)
Based on Oded Regev's code (which was based on Jacob Rus's fine "menu_click" code)
基于Oded Regev的代码(基于Jacob Rus的fine“menu_click”代码)