Take a screenshot and record a video in iOS Simulator

There would be a time when you need to capture your app screen or record a video of your app, whether for an App Store screenshot or an App Store preview video. You can do all of this without external tools.

Take a screenshot #

An easy way #

For taking a screenshot, I usually launch an app in the Simulator and press ⌘ - command + s or File > New Screen Shot. The screenshot will be saved to your Desktop.

xcrun is a tool Apple provided to run any tool inside Xcode from the command line.

To take a screenshot with xcrun. Run your app in the Simulator. Open Terminal.app (located in /Applications/Utilities) Enter the following command and hit ⏎ Return .

xcrun simctl io booted screenshot < file_name > . < file_extension >

The screenshot will be saved to your current directory. If you don't know where is the current directory, type pwd in Terminal.app and press ⏎ Return .

Example

xcrun simctl io booted screenshot myScreenshot.png

You can specify the following options to the command.

--type Can be "png", "tiff", "bmp", "gif", "jpeg". Default is png.

Can be "png", "tiff", "bmp", "gif", "jpeg". Default is png. --display iOS: supports "internal" or "external". Default is "internal". tvOS: supports only "external" watchOS: supports only "internal"

--mask For non-rectangular displays, handle the mask by policy: ignored: The mask is ignored and the unmasked framebuffer is saved. alpha: The mask is used as premultiplied alpha. black: The mask is rendered black.

For non-rectangular displays, handle the mask by policy:

Example

The following example will take a jpeg screenshot with a mask (see round corners and a notch).

xcrun simctl io booted screenshot -- type = jpeg -- mask = black myScreenshot . jpeg

Record a video #

When it comes to recording a video, xcrun is an easy way for me (I used to record video with Quicktime, but I find it quite cumbersome).

Run your app in the Simulator. Open Terminal.app (located in /Applications/Utilities) Enter the following command and hit ⏎ Return .

xcrun simctl io booted recordVideo < file_name > . < file_extension >

Press ⌃ – control + c to stop recording the video.

The video will be saved to your current directory. If you don't know where is the current directory, type pwd in Terminal.app and press ⏎ Return .

Example

xcrun simctl io booted recordVideo myVideo . mov

You can specify the following options to the command.

--codec Specifies the codec type: "h264" or "hevc". Default is "hevc".

Specifies the codec type: "h264" or "hevc". Default is "hevc". --display iOS: supports "internal" or "external". Default is "internal". tvOS: supports only "external" watchOS: supports only "internal"

--mask For non-rectangular displays, handle the mask by policy: ignored: The mask is ignored and the unmasked framebuffer is saved. alpha: Not supported, but retained for compatibility; the mask is rendered black. black: The mask is rendered black.

For non-rectangular displays, handle the mask by policy: --force Force the output file to be written to, even if the file already exists.

Example

xcrun simctl io booted recordVideo -- code = h264 -- mask = black -- force myVideo . mov

All xcrun command might vary based on your Xcode and mac version. For more information, run this command:

xcrun simctl io help

Related Resources #

Building from the Command Line with Xcode FAQ

Feel free to follow me on Twitter and ask your questions related to this post. Thanks for reading and see you next time.

If you enjoy my writing, please check out my Patreon https://www.patreon.com/sarunw and become my supporter. Sharing the article is also greatly appreciated.

Become a patron

Tweet

Share

← Home