How to Capture Website’s Screenshot Using Command Line

I know what you’re thinking: why bother with the command line for screenshots when I can just navigate to the website via a browser and take a screenshot using Mac’s keyboard shortcut or a screenshot tool?

Well, couple of reasons really.

Firstly, it’s genuinely enjoyable and useful to know. Secondly, using command lines allows for automation. You can duplicate commands, compile them into a script, and run it to batch capture screenshots of predetermined websites or URLs.

To take a screenshot on your Mac using the command line, here’s how to do it. Start by opening the Terminal app (duh!)

Next, you’ll need to adjust the following command to specify two key things:

  1. your screenshot’s saved location and its filename, and
  2. the URL of the website you want to capture.
/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome \
  --headless \
  --screenshot=/path/to/screenshot/image.png \
  https://www.domain.com

Let’s walk through an example. If you want to capture a screenshot of apple.com, name it "apple.jpg", and save it to a folder named "screenshots", this is how your command would look:

/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome \
  --headless \
  --screenshot=/screenshots/apple.png \
  https://www.apple.com

And this is what the screenshot will look like:

Standard apple.com screenshot

If you wish to customize the screenshot’s dimensions, you can do so by adding the following parameter:

--window-size=WIDTH,HEIGHT 

For instance, to capture a screenshot of apple.com at a resolution of 450×800, your command should be formatted as follows:

/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome \
  --headless \
  --window-size=450,800 \
  --screenshot=/screenshots/apple.png \
  https://apple.com

And here’s the resulting image:

Custom-size apple.com screenshot
WebsiteFacebookTwitterInstagramPinterestLinkedInGoogle+YoutubeRedditDribbbleBehanceGithubCodePenWhatsappEmail