Why use the terminal for screenshots?

Keyboard shortcuts work well for one-off captures, but they can't be scripted. If you need to capture a screenshot every 30 seconds, save it with a specific naming convention, capture a precise pixel region without manual selection, or integrate screen capture into a CI pipeline, you need the command line.

macOS ships with a built-in command called screencapture that does everything the keyboard shortcuts do — and more. It's been part of macOS since the early days and works in every version including the latest macOS Sequoia. No installation required, no Homebrew, no dependencies.

Basic usage

The simplest form captures your entire screen and saves it to a file:

screencapture screenshot.png

This saves a PNG file named screenshot.png in your current working directory. You can use any file path:

screencapture ~/Desktop/capture.png

The file format is determined by the extension. Use .png for lossless quality, .jpg for smaller files, or .pdf for vector-friendly captures:

screencapture capture.jpg
screencapture capture.pdf
screencapture capture.tiff

Interactive selection mode

The -i flag enables interactive mode, which works just like Cmd+Shift+4. Your cursor changes to a crosshair and you can select a region:

screencapture -i selection.png

Press Space during selection to switch to window capture mode, just like the keyboard shortcut. Click a window and it's captured with its shadow. Add -o to remove the window shadow:

screencapture -i -o clean-window.png

Window capture

The -w flag captures a specific window. It prompts you to click the window you want:

screencapture -w window.png

To capture a window without the drop shadow that macOS adds by default:

screencapture -w -o window-no-shadow.png

Capture a specific region by coordinates

The -R flag captures a precise rectangle without any user interaction. Specify the x, y, width, and height in pixels:

screencapture -R 100,200,800,600 region.png

This captures an 800×600 pixel rectangle starting at position (100, 200) from the top-left corner of your screen. This is the flag that makes automation possible — you can capture the exact same region repeatedly without manual selection.

Clipboard output

The -c flag sends the capture to your clipboard instead of saving a file:

screencapture -c

Combine with other flags for clipboard versions of any capture mode:

screencapture -c -i        # Interactive selection to clipboard
screencapture -c -w        # Window capture to clipboard
screencapture -c -R 0,0,500,400  # Region to clipboard

After running any of these, press Cmd+V to paste the screenshot into Slack, GitHub, or your AI coding assistant.

Timed captures

The -T flag adds a delay in seconds before the capture. This gives you time to set up the screen state you want to capture:

screencapture -T 5 delayed.png

This waits 5 seconds, then captures. Useful for capturing dropdown menus, tooltips, hover states, or any UI element that disappears when you switch to Terminal. Run the command, then quickly switch to the target app and trigger the element you want to capture.

Capture specific displays

If you have multiple monitors, the -D flag lets you choose which display to capture:

screencapture -D 1 main-display.png   # Main display
screencapture -D 2 second-display.png  # Second display

Without the -D flag, screencapture captures all screens in a single image or creates separate files if you provide multiple filenames:

screencapture screen1.png screen2.png

Useful flag combinations

Command What it does
screencapture -i -o file.png Interactive selection, no window shadow
screencapture -c -i Interactive selection to clipboard
screencapture -T 3 -i file.png 3-second delay, then interactive selection
screencapture -R 0,0,1920,1080 file.png Capture specific 1080p rectangle
screencapture -t jpg -x file.jpg JPEG format, no capture sound
screencapture -x file.png Full screen capture, silent (no sound)

The -x flag suppresses the camera shutter sound. The -t flag sets the image format explicitly, which is useful when the filename doesn't have an extension.

Scripting: automated screenshot capture

The real power of screencapture is in automation. Here are practical scripts you can use.

Time-lapse screenshots

Capture a screenshot every 30 seconds and save with timestamps:

#!/bin/bash
mkdir -p ~/Screenshots/timelapse
while true; do
  filename="capture-$(date +%Y%m%d-%H%M%S).png"
  screencapture -x ~/Screenshots/timelapse/"$filename"
  sleep 30
done

This is useful for monitoring long-running processes, recording your work for time-tracking, or documenting a multi-step procedure.

Capture with automatic naming

A shell alias that saves screenshots with readable timestamps:

# Add to ~/.zshrc
ss() {
  local dir=~/Screenshots
  mkdir -p "$dir"
  local file="$dir/$(date +%Y-%m-%d_%H-%M-%S).png"
  screencapture -i -o "$file"
  echo "Saved: $file"
}

Type ss in Terminal, select a region, and the file is saved with a clean timestamp name like 2026-04-01_14-30-22.png.

Capture and open in Preview

screencapture -i /tmp/quick-capture.png && open /tmp/quick-capture.png

This captures a region and immediately opens it in Preview for quick markup or inspection.

Capture and copy file path

ss-path() {
  local file="/tmp/screenshot-$(date +%s).png"
  screencapture -i "$file"
  echo "$file" | pbcopy
  echo "Path copied: $file"
}

After capturing, the file path is on your clipboard. Paste it into a Terminal command, a markdown document, or an image tag.

Integration with other tools

Pipe to ImageMagick

If you have ImageMagick installed, you can capture and process in one command:

# Capture and resize to 50%
screencapture -i /tmp/cap.png && magick /tmp/cap.png -resize 50% output.png

# Capture and convert to WebP
screencapture -i /tmp/cap.png && magick /tmp/cap.png output.webp

Capture and upload via curl

# Capture and upload to a file hosting API
screencapture -i /tmp/upload.png && \
  curl -F "file=@/tmp/upload.png" https://your-upload-endpoint.com/api/upload

Git commit with screenshot evidence

# Capture UI state and commit alongside code changes
screencapture -i docs/screenshots/feature-state.png
git add docs/screenshots/feature-state.png
git commit -m "docs: add screenshot of feature state"

Troubleshooting

Permission denied or blank captures: macOS requires screen recording permission for screencapture in some contexts. Go to System Settings → Privacy & Security → Screen Recording and ensure Terminal (or your terminal app like iTerm2) is enabled. You may need to restart your terminal after granting permission.

Captures are low resolution: On Retina displays, screencapture captures at native resolution by default (e.g., 3024×1964 on a 14" MacBook Pro). If you need display-resolution pixels (1512×982), resize the output with ImageMagick or sips: sips --resampleWidth 1512 screenshot.png

No sound on capture: That's the -x flag. If you want the shutter sound as confirmation, remove -x from your command.

When the terminal isn't enough

The screencapture command is powerful for automation and scripting, but it can't annotate. You can't add arrows, highlights, text, or blur regions before saving or sharing. For quick captures during active development — especially when you need to add visual context before pasting into Slack, GitHub, or an AI assistant — a GUI tool is faster.

LazyScreenshots bridges both worlds. For daily capture-annotate-paste workflows, it handles everything in one keystroke. For developers who live in the terminal, it complements screencapture by handling the annotation and sharing steps that the command line can't.

LazyScreenshots captures, annotates, and auto-pastes screenshots into Claude, Cursor, and ChatGPT. One keystroke for what the terminal takes a pipeline to do. $29 one-time.

Try LazyScreenshots — $29 one-time