Take screenshot of second monitor with python on OSX

霸气de小男生 提交于 2020-01-03 08:52:47

问题


I am trying to make an ambient light system with Python. I have gotten pyscreenshot to save a screenshot correctly, but I can't figure out how to get it to screenshot my second monitor (if this is even possible).

Is there a way to take a screenshot of my second monitor in Python using pyscreenshot (or something else)? I am using OSX Yosemite if that makes any difference.


回答1:


Use the built-in screencapture command and pass it 2 filenames. I believe it lives in /usr/sbin/screencapture so the command will look like this:

/usr/sbin/screencapture screen1.png screen2.png

I assume you know how to shell out to it using the subprocess module, along these lines

from subprocess import call
call(["/usr/sbin/screencapture", "screen1.png", "screen2.png"])



回答2:


Mark Setchell's answer is correct. Also this can't be done with pyscreenshot directly. If you look at the source, you'll notice that on Mac OSX they do use the screencapture utility but only pass it one file as an argument. The documentation (man screencapture) says that you have to pass in as many files as there are screens:

files – where to save the screen capture, 1 file per screen



来源:https://stackoverflow.com/questions/30037304/take-screenshot-of-second-monitor-with-python-on-osx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!