Take screenshot of second monitor with python on OSX

2024/10/14 21:19:25

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.

Answer

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"])
https://en.xdnf.cn/q/69370.html

Related Q&A

Invoking the __call__ method of a superclass

http://code.google.com/p/python-hidden-markov/source/browse/trunk/Markov.pyContains a class HMM, which inherits from BayesianModel, which is a new-style class. Each has a __call__ method. HMMs __call__…

Efficent way to split a large text file in python [duplicate]

This question already has answers here:Sorting text file by using Python(3 answers)Closed 10 years ago.this is a previous question where to improve the time performance of a function in python i need t…

Creating a unique id in a python dataclass

I need a unique (unsigned int) id for my python data class. This is very similar to this so post, but without explicit ctors. import attr from attrs import field from itertools import count @attr.s(aut…

How to get all the models (one for each set of parameters) using GridSearchCV?

From my understanding: best_estimator_ provides the estimator with highest score; best_score_ provides the score of the selected estimator; cv_results_ may be exploited to get the scores of all estimat…

How do I perform deep equality comparisons of two lists of tuples?

I want to compare two lists of tuples:larry = [(1,a), (2, b)] moe = [(2, b), (1, a)]such that the order of the items in the list may differ. Are there library functions to do this ?>> deep_equal…

Metadata-generation-failed when trying to install pygame [duplicate]

This question already has answers here:Python pygame not installing(3 answers)Closed last year.Trying to install pygame on python 3.11 using the following command "pip install pygame" and I a…

Why such a big pickle of a sklearn decision tree (30K times bigger)?

Why pickling a sklearn decision tree can generate a pickle thousands times bigger (in terms of memory) than the original estimator? I ran into this issue at work where a random forest estimator (with …

Buffer size for reading UDP packets in Python

I am trying to find out / adjust the size of network buffers:import socketsock = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)sock.getsockopt(socket.SOL_SOCKET,socket.SO_RCVBUF) 212992What on earth i…

Why does datetime give different timezone formats for the same timezone?

>>> now = datetime.datetime.now(pytz.timezone(Asia/Tokyo)) >>> dt = datetime(now.year, now.month, now.day, now.hour, now.minute, now.second, now.microsecond, pytz.timezone(Asia/Tokyo)…

Connect with pyppeteer to existing chrome

I want to connect to an existing (already opened, by the user, without any extra flags) Chrome browser using pyppeteer so I would be able to control it. I can do almost every manual action before (for …