Member-only story

How To Take A Screenshot From A macOS App Using Swift

Grace Huang
4 min readOct 24, 2022
The RedacApp I built was trying to capture the Safari window.

If you are building an image processing app on macOS, taking a screenshot on the screen and load it into the app directly is a straightforward way to import the image.

In this article, I will show you how to do it in your Swift code.

(My latest book “macOS App Development: The SwiftUI Way” is now available. Grab your copy today!)

Get familiar with the Screenshot app

On macOS, there is a native app called Screenshot.

Screenshot App on macOS

You can use this to screenshot the full screen, the selected window, or a selected area.

We will take advantage of this native app.

Run the CLI of the Screenshot app, and pick the command you need

Now, we need to figure out how to call the Screenshot app from the Terminal:

screencapture

Run screencapture -h, and you will see the options.

--

--

Grace Huang
Grace Huang

Written by Grace Huang

I write about startups, entrepreneurship, investing, software, hardware and manufacturing.

Responses (1)