Skip to content

Instantly share code, notes, and snippets.

@oguzhanvarsak
Last active March 26, 2021 16:12
Show Gist options
  • Save oguzhanvarsak/03803cf223bcfe1cf8ebd3173f7facbb to your computer and use it in GitHub Desktop.
Save oguzhanvarsak/03803cf223bcfe1cf8ebd3173f7facbb to your computer and use it in GitHub Desktop.
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

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

1- To take a screenshot with xcrun.

2- Run your app in the Simulator.

3- Open Terminal.app (located in /Applications/Utilities)

4- 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

Options

You can specify the following options to the command.

  • --type 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.

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

Xcrun

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).

1- Run your app in the Simulator.

2- Open Terminal.app (located in /Applications/Utilities)

3- Enter the following command and hit ⏎ Return.

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

4- 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

Options

You can specify the following options to the command.

  • --codec 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.
  • --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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment