I wanted to use screencapture
to take a screenshot of all monitors from within a script, but this only seems to capture the main monitor. How can I use screencapture
or any other tool callable from the command line to capture all monitors?
-
1I've edited your question to keep it (and potential answers) within the scope as defined in the FAQ.– nohillside ♦Commented Dec 11, 2013 at 13:02
1 Answer
It's poorly documented, but it is indeed possible with the screencapture
command.
screencapture ~/Desktop/screen1.png ~/Desktop/screen2.png [...]
Here's the relevant section from man screencapture
:
files where to save the screen capture, 1 file per screen
Of course, if you're calling it programmatically, you might not know how many monitors there are, so you'll have to parse the output of system_profiler SPDisplaysDataType
or defaults read /Library/Preferences/com.apple.windowserver.plist
to determine how many filename arguments to pass to screencapture
. For example:
$ system_profiler SPDisplaysDataType | grep "Online: Yes" | wc -l
2
References
https://stackoverflow.com/questions/20099333/terminal-command-to-show-connected-displays-monitors-resolutions
http://hintsforums.macworld.com/showthread.php?p=695603
-
thanks. I thought I tried with two filenames, but now it seems to work... Commented Dec 11, 2013 at 15:13
-
1It looks like passing extra arguments doesn't hurt anything so you could always specify like 10 files and assume you'll never have more than that many monitors!– dreevesCommented Oct 27, 2017 at 21:27