The keyboard shortcuts are the right tool for one screenshot at a time. They are the wrong tool when the capture is part of a repeatable process: documentation that needs the same window every release, a test step that has to save a frame on a schedule, or a support workflow that needs a timestamped file rather than a generic “Screenshot 2026-11-20 at 14.32.10.png”.

macOS ships everything you need for that. The command-line tool screencapture does the work, and Shortcuts, AppleScript and launchd are ways to run it. This guide goes from the flags that matter to the permissions that silently break the result.

The screencapture command

Open Terminal and run screencapture with a destination path:

screencapture ~/Desktop/shot.png

With no flags it captures the entire screen, writes a PNG, and plays the shutter sound. That is already useful, but the flags are what make it automation-friendly.

Flags worth knowing

Flag What it does
-i Interactive: select a region or window with the mouse
-x No shutter sound
-c Send the capture to the clipboard instead of a file
-t <format> Output format: png, jpg, pdf, tiff, gif, bmp
-R x,y,w,h Capture a fixed rectangle
-T <seconds> Wait before capturing
-m Only the main display
-D <display> Capture a specific display (1 is the main one)
-l <windowid> Capture a specific window by its window ID
-o In window mode, omit the window shadow
-C Include the mouse pointer (non-interactive modes)
-r Do not add screen DPI metadata

Two flags are easy to get wrong in scripts:

  • -i takes over the screen. It waits for a person to drag a selection or press Escape. It is not a background capture, so do not put it in a scheduled job.
  • -C and the pointer. Capturing the cursor only works in non-interactive modes; combining it with -i does not do what people expect.

Recipes

Full screen, silent, timestamped:

screencapture -x ~/Desktop/shot-$(date +%Y-%m-%d-%H%M%S).png

A fixed rectangle, useful when a window sits in a known position:

screencapture -x -R 0,0,1440,900 ~/Desktop/region.png

A region the user selects, saved only after they finish:

screencapture -i -x ~/Desktop/region.png

Copy to the clipboard for an immediate paste:

screencapture -x -c

A five-second delay, so you can arrange a menu or a hover state:

screencapture -T 5 -x ~/Desktop/delayed.png

A JPEG directly, skipping a conversion step:

screencapture -t jpg -x ~/Desktop/shot.jpg

A specific display, with no sound and no DPI metadata:

screencapture -x -D 2 -r ~/Desktop/second-display.png

A full-screen capture normally writes one file per display. Add -m when you only want the main screen, or -D when you want a particular one.

Capturing one window

-l takes a window ID, which you get from an app that exposes one. For apps that support it through AppleScript:

screencapture -x -l "$(osascript -e 'tell application "Safari" to id of window 1')" ~/Desktop/safari-window.png

This is fragile by nature: not every app returns a usable window ID, and the ID changes when the window is recreated. For a one-off window capture, ⌘⇧4 then Space is faster and more reliable. Use -l when the window identity is stable and the capture is part of a script.

AppleScript and shell scripts

AppleScript is useful for two jobs: running screencapture from an app-driven workflow, and controlling the app around the capture.

Running the command:

do shell script "screencapture -x ~/Desktop/shot.png"

Controlling another app before the capture requires Accessibility permission, not just Screen Recording:

tell application "Safari" to activate
delay 1
do shell script "screencapture -x ~/Desktop/browser.png"

The delay matters. activate returns before the window is necessarily on screen, and a capture taken too early can show the previous app. If the script sends keystrokes or clicks, macOS will ask for Accessibility access for the app running the script.

For anything longer than a few lines, a shell script is easier to version and debug:

#!/bin/zsh
set -euo pipefail
out="$HOME/Desktop/shot-$(date +%Y-%m-%d-%H%M%S).png"
screencapture -x "$out"
echo "$out"

The echo is not decoration: when the script is called by another tool, printing the path is how the caller finds the file.

Shortcuts

Shortcuts is the visual option, and it is the easiest way to combine a capture with other steps such as resizing, renaming or copying text out of the image.

  1. Open Shortcuts and create a new shortcut.
  2. Search for Take Screenshot and add the action.
  3. Choose Full Screen, Window or Interactive. For a region, open Show More and set the selection to Custom.
  4. Add a Save File action and pick a folder, or add Copy to Clipboard.
  5. Give the shortcut a name, then run it from the menu bar, from Spotlight, or with a keyboard shortcut you assign in Shortcuts.

A shortcut can also run a shell command, which is the escape hatch when the built-in action is not flexible enough:

  1. Add Run Shell Script.
  2. Paste a screencapture command.
  3. If the action is missing or disabled, check Shortcuts’ advanced settings for script actions and enable them only for commands you understand.

To run a shortcut from a script or a scheduler:

shortcuts run "Screenshot to Desktop"

Shortcuts is the right layer when a non-developer needs to trigger the capture. It is the wrong layer when you need precise flags, multiple displays or a guaranteed output path, because the built-in action hides those details.

Permissions: the usual reason automation fails

A script that works in Terminal can produce a black image, a desktop-only image, or no file at all when it runs from another context. The cause is almost always Screen Recording permission.

  • Open System Settings → Privacy & Security → Screen & System Audio Recording (older macOS versions call it Screen Recording).
  • Enable the app that is actually running the command: Terminal, iTerm, Shortcuts, or the app hosting your script.
  • Quit and reopen the app after changing the permission. macOS often asks for this explicitly.

Related permissions:

  • Accessibility is required to send keystrokes or clicks from AppleScript or a shortcut. It is not required for a plain screencapture.
  • Automation permission appears when one app controls another, for example a script telling Safari to activate.
  • Full Disk Access is not normally needed for screenshots; do not grant it just to fix a capture.

Two content-level limits are not permission problems:

  • Secure input fields can appear blank in a capture even when everything is configured correctly. That is the system protecting password entry.
  • Protected video windows may not be capturable. Apple notes that some apps, such as Apple TV and DVD Player, can refuse window captures.

Scheduling captures

For a repeated capture, use launchd rather than an interactive tool. A LaunchAgent runs your script on a schedule or at login, with the same user session and the same permissions as the logged-in user. Cron still exists on macOS but is discouraged for anything that touches the GUI, because it has no access to the user’s window server session.

Two caveats apply to every scheduler:

  • The screen must be available. A locked or sleeping Mac will not produce a useful capture.
  • The permission belongs to the process. If launchd runs a script through /bin/zsh, grant Screen Recording to the terminal or wrapper that launches it, and test the scheduled path rather than only the interactive one.

For most teams, the simpler arrangement is a Shortcut bound to a keyboard shortcut or a menu bar item, run by a person at the moment the screen is in the right state. Automate the naming, the format and the destination; leave the timing to a human unless the capture genuinely needs to be unattended.

When a GUI app is the better automation

Command-line captures are exact but blind: they cannot see whether the window is ready, whether a banner is covering the content, or whether the page has finished loading. A menu bar utility that opens an editor and a share action covers the human part of the loop, and the scripts above cover the repeatable part. Pick the boundary deliberately: script the capture and the file handling, and keep the review step in front of a person.

Quick reference

Goal Command
Full screen, silent screencapture -x shot.png
Region, interactive screencapture -i -x region.png
Fixed rectangle screencapture -x -R 0,0,1440,900 region.png
Clipboard screencapture -x -c
Delay screencapture -T 5 -x shot.png
JPEG screencapture -t jpg -x shot.jpg
Main display only screencapture -x -m shot.png
One specific display screencapture -x -D 2 shot.png
Run a shortcut shortcuts run "Name"

Sources and further reading