Member-only story
How To Take A Screenshot From A macOS App Using Swift
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.
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.