xcrun simctl 操作模拟器的命令
Xcode安装之后,simctl可以通过xcrun命令来执行。
你可以通过直接输入xcrun simctl
来查看它支持的作用。
usage: simctl [--set <path>] [--profiles <path>] <subcommand> ...
simctl help [subcommand]
Command line utility to control the Simulator。
通过这个命令可以方便地控制模拟器。
管理设备xcrun simctl list
通过运行xcrun simctl list
可以获取到当前可用的设备列表,包括设备类型、设备系统版本、设备名称、设备UUID,运行状态等信息。
每个设备都有一个独一无二的UUID,这个是其他simctl
子命令需要的参数
For subcommands that require a <device> argument, you may specify a device UDID
or the special "booted" string which will cause simctl to pick a booted device.
If multiple devices are booted when the "booted" device is selected, simctl
will choose one of them.
因为部分子命令需要 设备参数,你可以通过指定设备的UUID或booted
让命令自行选中一个已经启动的设备。如果多个模拟器已经启动,simctl将选择其中的一个。
启动模拟器 xcrun simctl boot $UUID
用来启动模拟器,其中的UUID参数就是之前列表中的UUID。
既然有启动模拟器,自然也就有关闭模拟器xcrun simctl shutdown $UUID
、重置模拟器xcrun simctl erase $UUID
清理不可用的模拟器 xcrun simctl delete unavailable
当Mac空间不够用时,这条命令或许可以帮你重获不是磁盘空间。
在模拟器与Mac设备之间进行复制&粘贴pbcopy
& pbpaste
pbcopy
复制内容到Mac设备的剪贴板pbpaste
将 Mac设备的剪贴板的内容进行粘贴xcrun simctl pbcopy booted
将Mac设备中剪贴板上的内容复制到模拟器上的剪贴板上 【方向:Mac=》模拟器】xcrun simctl pbpaste booted
将模拟器中剪贴板上的内容复制到Mac设备上的剪贴板上 【方向:模拟器=》Mac】xcrun simctl pbsync sourceDevice destDevice
将source设备中剪贴板上的内容同步到dest设备上的剪贴板上 【方向:source《=》dest】,其中可以用 host 表示Mac设备
模拟器截屏 xcrun simctl io booted screenshot app-screenshot.png
模拟器录屏 xcrun simctl io booted recordVideo app-preview.mp4
执行命令后,录制完成时"Ctrl + C"结束,这个时候到指定位置找响应的视频文件即可
设置模拟器位置
指定UUID的数据目录~/Library/Developer/CoreSimulator/Devices/
,
模拟器偏好文件位于data/Library/Preferences/.GlobalPreferences.plist
,里面包含许多设置,
可以通过plutil
命令来查看,具体如下:
plutil -p ~/Library/Developer/CoreSimulator/Devices/$UUID/data/Library/Preferences/.GlobalPreferences.plist
同样,修改也是通过plutil
来实现,示例如下:
PLIST=~/Library/Developer/CoreSimulator/Devices/$UUID/data/Library/Preferences/.GlobalPreferences.plist
LANGUAGE="ja"
LOCALE="ja_JP"
plutil -replace AppleLocale -string $LOCALE $PLIST
plutil -replace AppleLanguages -json "[ \"$LANGUAGE\" ]" $PLIST
更多功能可以通过plutil -h
来查看
其他更多功能,请查看命令帮助文件
附录:完整命令帮助说明
Subcommands:
create Create a new device.
clone Clone an existing device.
upgrade Upgrade a device to a newer runtime.
delete Delete a device or all unavailable devices.
pair Create a new watch and phone pair.
unpair Unpair a watch and phone pair.
pair_activate Set a given pair as active.
erase Erase a device's contents and settings.
boot Boot a device.
shutdown Shutdown a device.
rename Rename a device.
getenv Print an environment variable from a running device.
openurl Open a URL in a device.
addmedia Add photos, live photos, videos, or contacts to the library of a device.
install Install an app on a device.
uninstall Uninstall an app from a device.
get_app_container Print the path of the installed app's container
launch Launch an application by identifier on a device.
terminate Terminate an application by identifier on a device.
spawn Spawn a process by executing a given executable on a device.
list List available devices, device types, runtimes, or device pairs.
icloud_sync Trigger iCloud sync on a device.
pbsync Sync the pasteboard content from one pasteboard to another.
pbcopy Copy standard input onto the device pasteboard.
pbpaste Print the contents of the device's pasteboard to standard output.
help Prints the usage for a given subcommand.
io Set up a device IO operation.
diagnose Collect diagnostic information and logs.
logverbose enable or disable verbose logging for a device