How to Use the ‘screencapture’ Command for Automated Screenshots via Terminal

The Need for Programmatic Screenshots

Every Mac user knows the graphical keyboard shortcuts for taking screenshots (Command + Shift + 3 for the whole screen, or Command + Shift + 4 for a selection). But what if you are writing a bash script to automatically capture the screen every hour for a time-lapse? What if you are SSH’d into a remote Mac server and need to see what is currently displaying on its physical monitor?

You cannot use keyboard shortcuts in a script or over an SSH connection. For automated, programmatic image capture, macOS provides the screencapture terminal command.

1. Basic Full-Screen Capture

To take a screenshot of the entire screen and save it to your Documents folder, simply provide the file path:

screencapture ~/Documents/my_screenshot.png

The command executes instantly, mimicking the behavior of Command + Shift + 3, but bypassing the graphical interface entirely.

2. Capturing with a Timer Delay

Often, you need a few seconds to arrange windows or open a dropdown menu before the screenshot is taken. You can use the -T (Time) flag to specify a delay in seconds.

screencapture -T 5 ~/Documents/delayed_shot.png

The terminal will wait exactly 5 seconds before capturing the image.

3. Hiding the Mouse Cursor

By default, screencapture includes the mouse pointer in the image (if it is hovering over the capture area). For professional documentation or clean time-lapses, you usually want to hide the cursor. Use the -C flag.

screencapture -C ~/Documents/clean_shot.png

4. Disabling the Shutter Sound

If you are running an automated script that takes a screenshot every 60 seconds in a quiet office, the loud, artificial camera shutter sound will quickly become infuriating. You can silence the command using the -x flag.

screencapture -x ~/Documents/silent_shot.png

5. Capturing Only a Specific Window

If you don’t want the entire desktop, you can tell screencapture to capture a specific window. This requires the -l (lowercase L) flag, followed by the Window ID.

(Finding the exact Window ID usually requires an external tool or complex AppleScript, but there is a brilliant workaround).

Instead of finding the ID, use the -W flag. This tells the command to wait for you to click on the window you want to capture.

screencapture -W ~/Documents/window_shot.png

Your cursor will turn into a camera icon. Click on the Safari or Terminal window, and it will capture only that specific window, complete with a beautiful drop shadow.

6. Copying to the Clipboard Instead of a File

If you are writing a script that pipes the image into another application (like a Slack bot), you might not want to clutter the hard drive with temporary PNG files. You can use the -c flag to send the captured image directly to the macOS clipboard.

screencapture -c

Conclusion

The screencapture utility bridges the gap between the graphical macOS interface and the powerful automation capabilities of the terminal. By utilizing flags for delays, cursor hiding, and silent execution, developers can build robust screen-monitoring and documentation scripts that run seamlessly in the background.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.